From a4399a184a109e483720057ff6aecb83cd437513 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 16 Sep 2024 15:49:37 +0200 Subject: [PATCH 1/2] Rust: introduce `Unextracted` and `Missing` "marker" classes --- rust/ql/.generated.list | 18 +++--- rust/ql/.gitattributes | 4 ++ rust/ql/lib/codeql/rust/elements.qll | 2 + .../lib/codeql/rust/generated/MissingExpr.qll | 3 +- .../lib/codeql/rust/generated/MissingPat.qll | 3 +- .../lib/codeql/rust/generated/ParentChild.qll | 48 +++++++++++++-- rust/ql/lib/codeql/rust/generated/Raw.qll | 23 ++++++-- rust/ql/lib/codeql/rust/generated/Synth.qll | 58 ++++++++++++++++++- .../codeql/rust/generated/Unimplemented.qll | 4 +- rust/ql/lib/rust.dbscheme | 22 +++++-- rust/schema.py | 27 +++++++-- 11 files changed, 178 insertions(+), 34 deletions(-) diff --git a/rust/ql/.generated.list b/rust/ql/.generated.list index 3c6334648d55..e7593aaa0210 100644 --- a/rust/ql/.generated.list +++ b/rust/ql/.generated.list @@ -68,6 +68,7 @@ lib/codeql/rust/elements/MatchExpr.qll 6938b5b9aca51f15cc0c0c6374a5845c9c298cb49 lib/codeql/rust/elements/MatchExprConstructor.qll 74df937d7d8bfbfb02bdbf095595eb3f2129ed4c0854bae6d73b5b38d4fc902d 5c388c02f02462d843945111b72de12bce33c7c332d55993d903aeb250213407 lib/codeql/rust/elements/MethodCallExpr.qll e92c5214160d6b5bebba76c78f5ec0380a629230991513326585c99dab7be1f3 ed05c7f40fb6d1c97fa0a3a631db1913b8e6abb5c2b3513d0e81a82a2e5f7f95 lib/codeql/rust/elements/MethodCallExprConstructor.qll c9e1137ba6b76eabd941ecaa27a5b43b6fc3ff445ad46d3f625ad086de0e0af6 47bc4c30182b891c7009ba536edad7393dc068b72d9dfc16b26174b15d49748e +lib/codeql/rust/elements/Missing.qll c4dbdfe0ef96ff74ef6bf5979028f357cf6494cf9b96de200eb3cc4190392f6e 1b9efbc1ea3d36d363ba8c408f10acd8d8a24147e56254df7914a499e69f889d lib/codeql/rust/elements/MissingExpr.qll 618f80b813afda19783c689c67c79b2106483b559f49dc21ed713281d6b1ac87 9de89e36754a98b8caf9010690ceb8a9d32999d192e325a1a24892311f874268 lib/codeql/rust/elements/MissingExprConstructor.qll c51f4f6e897ef2107a27bd91ecf31ce875611b29a5a12238d5312b9489a35b8d b9ea3fdae459aba6c7ed9eb48edbc5bdbdb4cb41220fff81ed4cd256648612e0 lib/codeql/rust/elements/MissingPat.qll a2d6ee4f7bbb69b9c05026b71c0283a6b229a7eaf492894296294fbe533e40d9 c9823a3a06ff2ff25ad3f7ca573f122637571f7d351bfd1f7f339c7629404852 @@ -120,6 +121,7 @@ lib/codeql/rust/elements/TypeRef.qll 13824c88938542cc554bc9ead335136a4eb115ec07c lib/codeql/rust/elements/TypeRefConstructor.qll f8b2e5ef15517890a8b2d56643f471ae64cc74c420187049e33b182417e72e4f 683611e732b842756e301a77625b385bca0c4969971020c9e11220a1aa665a29 lib/codeql/rust/elements/UnderscoreExpr.qll bf4c0bf76fa15b041f7ecbd492a499088bef2024b49dbdfa57232e84e72c3067 462380bac5f772c1986146d32b70deabc9f03581675f6e79f7b7f747acfb0bd5 lib/codeql/rust/elements/UnderscoreExprConstructor.qll ea9f93fa6529ec4e5bf5c4a98959b2e013e83fce4a74ebfc476b10bce2b331b2 bc36b62fd4fec6fb388d82e2af2aafe0099138d54b7672be81e84fc511fdcc8f +lib/codeql/rust/elements/Unextracted.qll 2179610843dd7acc0a5afedd8c12b088a5a70b9a00a174501cf23f3ff46c24f5 cf8433155683f6d3c6f305190f93fe8e270f9fa8cab181b2e28dc81d19cade7d lib/codeql/rust/elements/Unimplemented.qll 8736c0b7ab0a5b558b47cffe579c0e56016de10017235502bbe18a6d81510a8e cdb6135c0065938892fb32020a7041eed103d97c3335cdc1bf837046f80bd8d3 lib/codeql/rust/elements/UnimplementedDeclaration.qll ec261842f0257b4f512a92911408110e9e48f975a2bf0a56524a57a5c8e694b8 6682484339cb3b9b08f15949b37ee380ab6a15e96517be21cface664a9c1d9d5 lib/codeql/rust/elements/UnimplementedDeclarationConstructor.qll 44f4590db81e7504de0ede43eb2a33a54baa0738732e03a90721187a1cd303f3 11f27d8a9836b78d9ffac79efa3441fbfcb1dfdc1eb028d2016a1769b8a82ad5 @@ -131,7 +133,7 @@ lib/codeql/rust/elements/YeetExpr.qll 95a15d0ae79b9cad126700c07d5cb7e4e9699e2e5d lib/codeql/rust/elements/YeetExprConstructor.qll f1871c6e0c966c52806e370dbe2956585bbfa1dcf0bd7ebfdb2bd39b7cfd0d7b a2333e80a325a921a66c34151401da12c250951952ccb0c81e5102dc62299503 lib/codeql/rust/elements/YieldExpr.qll 72682ae19d37abd6ec26569ae8f575979ebba1e0d373898211a9af4fad4979a1 ef0193011ee5f94cebbac5c007d652568f560685a213bf8be96cd0c0983a3880 lib/codeql/rust/elements/YieldExprConstructor.qll ff46ba17cc24abfcb0e310c7458d0539b704e7a771ad00853bd3a1844e4e6f82 1c13662ef01c88f1cf057d099eb46524036133e51a0e36ddf947f727ac6046bb -lib/codeql/rust/elements.qll 1d92fc19e7660d9874f0dc26a85a7021aaffa05a4c84dd847a82606e7235b944 1d92fc19e7660d9874f0dc26a85a7021aaffa05a4c84dd847a82606e7235b944 +lib/codeql/rust/elements.qll ce8f8d6cb6025ea700e355813c943b7d3d00eabf9a459b3f7f8245f03d147bc4 ce8f8d6cb6025ea700e355813c943b7d3d00eabf9a459b3f7f8245f03d147bc4 lib/codeql/rust/generated/ArrayExpr.qll 3fd7465da22e1eb810ae28ffab7b14e9ccceaab0082aa665f14b73d4221128b8 6e9edb5846656aad90283406a496aaae485d38854075a4443817b5098b72b427 lib/codeql/rust/generated/AsmExpr.qll 66f1a4bfb4d32d99b4dab1918a1aac75e0903c499d65a18105e3c837c1aa314d cd5c8ed300b5f5d19e404cd2e5f9dcbcee1081c5538f1840359eb491eb6ecaa2 lib/codeql/rust/generated/AstNode.qll 0598fac7859906f4103124270dfb2fbdb838387b1c45000bf50a4b62c797ec41 f47c84878c7c9676109e358073bddab92a1dbeb4d977d236ecc1eae44d81c894 @@ -172,12 +174,13 @@ lib/codeql/rust/generated/LoopExpr.qll ddc646e715dced161b60638ac36a7671b45ddd624 lib/codeql/rust/generated/MatchArm.qll e4e129ac42537138a3f5d288113ee805b49a5c914cf44564e59be389e07d6eda 5e5ae462925501265237f06a68549d5a26e01864386d16d0e28a12305127cb71 lib/codeql/rust/generated/MatchExpr.qll 74966bd8286aa8cd4238c5f6964b5668d3f95fd47a56fcece47fbd0abe3a8376 9afcc11f0af8e5daee2746226b2c39bec0f9cbc74d0cb1bf567a8ea122409331 lib/codeql/rust/generated/MethodCallExpr.qll 187d28d3869f5b44cca8420948266e8370ca1e3e389dc3317dc24364c8d53088 7a4744cce29b53ca04b6b2eaf4fd146b9a64e3f53151e5c6cd1085fc35d50823 -lib/codeql/rust/generated/MissingExpr.qll 34cb27c927a62cc06b0fe26a085e2658abd5019e549c3e01b8273d99e9a9616f 34bf4cfbf3659b600b4aac121f7c2d6da0b00b61c3002f8fb1d554c11968c748 -lib/codeql/rust/generated/MissingPat.qll 40fa87d446056c7263ef5843fb13fe60b644e169a65697be4ca0b5361a8267ee 40fa87d446056c7263ef5843fb13fe60b644e169a65697be4ca0b5361a8267ee +lib/codeql/rust/generated/Missing.qll d864b8d6f6f86638529c19204a50393e7cbfdfa99d56f3fb0f03492e823cbe36 5476a516b66e904ac14ef0aaf176ace40d3195886568c42468d191997fe788e7 +lib/codeql/rust/generated/MissingExpr.qll 258bb649ba4498bf4bda25db051355f8465514a86f41ee9cd9a04a7b3b1177c7 0a66744cdb3600cc4d4c050a28318c25def3af9e9f0756ed7142d9433795dde8 +lib/codeql/rust/generated/MissingPat.qll 194784eeab6f41c62abe6f93c5e0d84d63182d068fd1371f156c1499170f83ad 194784eeab6f41c62abe6f93c5e0d84d63182d068fd1371f156c1499170f83ad lib/codeql/rust/generated/Module.qll c6007444c796654fb48fbe4a4596580f08feec2aac13932043062a170dd73f0b 0560c738dbee3937baf0f2ab661c8e4dacd69eb886635241b1ff90f2c0f4bd67 lib/codeql/rust/generated/OffsetOfExpr.qll 03afe5637df806f4649fb2c67fdc4f048a2faab47f00e8320f85025d4a2fa933 4e5c0c98b0397f1388ac0c27ea415f594ebd591e980dd70590ed043856beb156 lib/codeql/rust/generated/OrPat.qll 52e637c652f8caf64d2388a1829159d187d3799384cc3318e07785f518ff0c4b 598a11d067519bb7bb279d8f8a3ea85a48ae99c2974182636c157ba111b9605e -lib/codeql/rust/generated/ParentChild.qll 98033de64e7d2db6f3574e0220aad773d04170aed7bf2b97ed4d97278f5837c5 5d9cd7f051f89df726af0fad1ccf8e2a456def82418397155a33858c58962364 +lib/codeql/rust/generated/ParentChild.qll 9b6a6792d8a18d5ef37f17ca6d68651bdd6798fda621c415144b6b803ba53c3a 630a7898e8c02a5ece5d4d21659d16c24e339469130c89711100764d56969243 lib/codeql/rust/generated/Pat.qll b035e7866ea500232421ef9f79e7e60b90b9c27dbe47d25758548e94750d2965 adf701ad35559ea7d0284d6718ad507518778dc78100f48063e6a6bf3705c91f lib/codeql/rust/generated/Path.qll ffd26e9e5e3878f374bc1163d6ccb47072cc1d3abd937d0206bf1a7c62c843ff ffd26e9e5e3878f374bc1163d6ccb47072cc1d3abd937d0206bf1a7c62c843ff lib/codeql/rust/generated/PathExpr.qll c27d872e3351d92f8f105c6a4ae2f8f447209a4a139e00576986e641340d9e7d bb5bd1fed0d5caeac3c14d57ca8ee5d3ece8938aab753d488ff475bda8393229 @@ -186,7 +189,7 @@ lib/codeql/rust/generated/PrefixExpr.qll a3f6cc62e5a12acd253ea59cb6957fb7157aa70 lib/codeql/rust/generated/PureSynthConstructors.qll 5eb1fc4f6a04172c34ae31e4931e4bf1f8b72fbe414c5f644731a45372d13573 5eb1fc4f6a04172c34ae31e4931e4bf1f8b72fbe414c5f644731a45372d13573 lib/codeql/rust/generated/RangeExpr.qll 1678fa524166552a36d73cad9d34213309b1989c1e427bc990b5c11a12588ce5 beb90978cea26a2ec9d3e8cc7b0b6a728ae952212ada5d6ad19319120f3218a8 lib/codeql/rust/generated/RangePat.qll 2e96aece5ff2300659c2729c7037f7334790456d86160dc1e16ae99545c6ed0d eae4f95f9eaacbc2319ee67556dcc164527d82a6eaa5af59f6efce9caf3cba3b -lib/codeql/rust/generated/Raw.qll 358a5b315ed73e67446de7d4c32a6430832fa7cbf62f2be3ee0100c494ff3764 6b9628a5e9a8d6d953f87d332520652654292932225abc4d60c6a1dba1cd369c +lib/codeql/rust/generated/Raw.qll d876ce05f7dd89eee1677c52f97b84c352705f63e6382f07782fb2a34938fe98 9a811e7d876e8fffd3564787221e39f954100abc67a6f550af6f7e1b70e44551 lib/codeql/rust/generated/RecordExpr.qll bdafc10cde139617b67cb46bb205f99bc3fc0b9fd8634d304b81b524b9592aa8 2826c453c72416237467b08cf9ad9421b03203a8593420146dad8e1e71711b8a lib/codeql/rust/generated/RecordExprField.qll eb06236fbdb856169dfe50ae1ebf59384222de6670ca91c34eed647823dda4ce 750bc7ab1e156db3927d6dd206e9d2c9388519425c0e8665afd322a6594aa5e2 lib/codeql/rust/generated/RecordPat.qll 20b62cfd4ee4e911ad4a2b8e5762da2abb7ff0c1d7f21cc6f72b1ebcbebbcd42 c0502e6bfc637058524cf7369c63396ca5440c58e5e91600fecd35ca5299d86c @@ -197,14 +200,15 @@ lib/codeql/rust/generated/RepeatExpr.qll 5a33101a5e2ba973beafe0d933ad5ca238050eb lib/codeql/rust/generated/ReturnExpr.qll 3d8fffeb6420a35d78f4f2e2e3e4ccf1c8454022c50395be2e8446f29740ddfa cc9dd916dc18114469d2eed9b82f83518af0de78797ad98777b29a5055bc77df lib/codeql/rust/generated/SlicePat.qll 73dce5e310068357eb41e8c51923ff5c4054548db27987cde85735ddf071fc44 67fa0c285c110f18446689d1eaad9e82896df79d62999ad3f788fc295fa1d2c3 lib/codeql/rust/generated/Stmt.qll 58b010f32956f2736a7b9ebb43467ecd03308a1f27c99e2b09bb925c349ac859 9859da4a4aa29b4f7ab47313b2dfe8baf9717a162fcd8bd62a7cbab4afd1886e -lib/codeql/rust/generated/Synth.qll 69415291e37195836bcc6810cccfdbacad4e1528bb125e26d2cc6b53daf1666b 6c79ab425ea2e132a2bc0eeea4f9f62cf3e259e911deb0c02c9fbdd56957e291 +lib/codeql/rust/generated/Synth.qll e01241112720e440391394b022405e0f5d5fa8c09f9de2f2d2ac1d66b548f9c7 b23b3489ed588352f862558e824d03be8507f3418d31b3908578af59c545d761 lib/codeql/rust/generated/SynthConstructors.qll ff41f7bac5ae52e0eb4db378ddd389d65209d927046743852071650b86b4066a ff41f7bac5ae52e0eb4db378ddd389d65209d927046743852071650b86b4066a lib/codeql/rust/generated/TupleExpr.qll 0828181e2f1f1f233598eab367688615356f6b91451a40f8d812d247d93467fc 2473c52d3dfbec6c8cd66bd439c85959e854f617edf5afe545252a24304f2f2e lib/codeql/rust/generated/TuplePat.qll a1b22c20ca02497e9be8c6edaeaff214a669ecb0d2493890e79c28c485f512a1 5cc082ea99de61662b2d4c8b59f7a833236e7e448943e8ee894ab6066cc761c4 lib/codeql/rust/generated/TupleStructPat.qll 089563349c9866f5703e9d306ba2a475d7d4002e7236dbbf2feeb89290b4d24c a77842d7262a7d19b175f239d1ee6550b3b66a4efe903c5112bb82c0abd7b05d lib/codeql/rust/generated/TypeRef.qll 62cda2a3bd01a8c8356f11e5deb38ead4a8af630df27d88b8f60b5458d263527 62cda2a3bd01a8c8356f11e5deb38ead4a8af630df27d88b8f60b5458d263527 lib/codeql/rust/generated/UnderscoreExpr.qll 964b77ddae265ad51fd03fcb7ef008fcb34eb5ea1a7ac0cd06ed84c1922fc07f 964b77ddae265ad51fd03fcb7ef008fcb34eb5ea1a7ac0cd06ed84c1922fc07f -lib/codeql/rust/generated/Unimplemented.qll bcf63c2be3e0f7b88704a76ed182616101cd4b317f539ef5a65e5a4b87fb6b39 0e3e0ba85e03f327334b752c1dd1aa82b71bf1601725fcc071d93a29e40e1188 +lib/codeql/rust/generated/Unextracted.qll 815b051a9a05c0665affca8a0e208657d34fdf645d370b768d0c620d9d9bc5e7 9ca254998085470ab105c03659620a46c7ad6b92f62ca3383daff3f3a56d6b40 +lib/codeql/rust/generated/Unimplemented.qll bc1846cf521c4c2235c58027441127d93a769a2075314d333bbb298aacae6604 7a1bcbbda994ed0e8e310c0c5f762070e2e716417b4c89ee2dab227bad14ff95 lib/codeql/rust/generated/UnimplementedDeclaration.qll a6eb4e61be018288304be010e063b68039a97f2cfe19e7049d3d54c65c88e9ab 662da5c38f5907d1f0f9990caca2114bf5e3b179591104dde777ae67262815df lib/codeql/rust/generated/UnsafeBlockExpr.qll 52edde0daa57fea065f06537db05b5d442c63b3fa8777bf55ef2b2106c228ee9 52edde0daa57fea065f06537db05b5d442c63b3fa8777bf55ef2b2106c228ee9 lib/codeql/rust/generated/WildcardPat.qll 84da49dc571151b0c5e0661426546a53d499ce37fe927ca07f67c4977dd70e16 84da49dc571151b0c5e0661426546a53d499ce37fe927ca07f67c4977dd70e16 diff --git a/rust/ql/.gitattributes b/rust/ql/.gitattributes index 753ae9b6790d..3c5c95c70c22 100644 --- a/rust/ql/.gitattributes +++ b/rust/ql/.gitattributes @@ -70,6 +70,7 @@ /lib/codeql/rust/elements/MatchExprConstructor.qll linguist-generated /lib/codeql/rust/elements/MethodCallExpr.qll linguist-generated /lib/codeql/rust/elements/MethodCallExprConstructor.qll linguist-generated +/lib/codeql/rust/elements/Missing.qll linguist-generated /lib/codeql/rust/elements/MissingExpr.qll linguist-generated /lib/codeql/rust/elements/MissingExprConstructor.qll linguist-generated /lib/codeql/rust/elements/MissingPat.qll linguist-generated @@ -122,6 +123,7 @@ /lib/codeql/rust/elements/TypeRefConstructor.qll linguist-generated /lib/codeql/rust/elements/UnderscoreExpr.qll linguist-generated /lib/codeql/rust/elements/UnderscoreExprConstructor.qll linguist-generated +/lib/codeql/rust/elements/Unextracted.qll linguist-generated /lib/codeql/rust/elements/Unimplemented.qll linguist-generated /lib/codeql/rust/elements/UnimplementedDeclaration.qll linguist-generated /lib/codeql/rust/elements/UnimplementedDeclarationConstructor.qll linguist-generated @@ -174,6 +176,7 @@ /lib/codeql/rust/generated/MatchArm.qll linguist-generated /lib/codeql/rust/generated/MatchExpr.qll linguist-generated /lib/codeql/rust/generated/MethodCallExpr.qll linguist-generated +/lib/codeql/rust/generated/Missing.qll linguist-generated /lib/codeql/rust/generated/MissingExpr.qll linguist-generated /lib/codeql/rust/generated/MissingPat.qll linguist-generated /lib/codeql/rust/generated/Module.qll linguist-generated @@ -206,6 +209,7 @@ /lib/codeql/rust/generated/TupleStructPat.qll linguist-generated /lib/codeql/rust/generated/TypeRef.qll linguist-generated /lib/codeql/rust/generated/UnderscoreExpr.qll linguist-generated +/lib/codeql/rust/generated/Unextracted.qll linguist-generated /lib/codeql/rust/generated/Unimplemented.qll linguist-generated /lib/codeql/rust/generated/UnimplementedDeclaration.qll linguist-generated /lib/codeql/rust/generated/UnsafeBlockExpr.qll linguist-generated diff --git a/rust/ql/lib/codeql/rust/elements.qll b/rust/ql/lib/codeql/rust/elements.qll index 64342d92af2c..f72a983f89e9 100644 --- a/rust/ql/lib/codeql/rust/elements.qll +++ b/rust/ql/lib/codeql/rust/elements.qll @@ -43,6 +43,7 @@ import codeql.rust.elements.LoopExpr import codeql.rust.elements.MatchArm import codeql.rust.elements.MatchExpr import codeql.rust.elements.MethodCallExpr +import codeql.rust.elements.Missing import codeql.rust.elements.MissingExpr import codeql.rust.elements.MissingPat import codeql.rust.elements.Module @@ -70,6 +71,7 @@ import codeql.rust.elements.TuplePat import codeql.rust.elements.TupleStructPat import codeql.rust.elements.TypeRef import codeql.rust.elements.UnderscoreExpr +import codeql.rust.elements.Unextracted import codeql.rust.elements.Unimplemented import codeql.rust.elements.UnimplementedDeclaration import codeql.rust.elements.UnsafeBlockExpr diff --git a/rust/ql/lib/codeql/rust/generated/MissingExpr.qll b/rust/ql/lib/codeql/rust/generated/MissingExpr.qll index 955d662bce41..26ccefc26fae 100644 --- a/rust/ql/lib/codeql/rust/generated/MissingExpr.qll +++ b/rust/ql/lib/codeql/rust/generated/MissingExpr.qll @@ -7,6 +7,7 @@ private import codeql.rust.generated.Synth private import codeql.rust.generated.Raw import codeql.rust.elements.Expr +import codeql.rust.elements.Missing /** * INTERNAL: This module contains the fully generated definition of `MissingExpr` and should not @@ -22,7 +23,7 @@ module Generated { * INTERNAL: Do not reference the `Generated::MissingExpr` class directly. * Use the subclass `MissingExpr`, where the following predicates are available. */ - class MissingExpr extends Synth::TMissingExpr, Expr { + class MissingExpr extends Synth::TMissingExpr, Expr, Missing { override string getAPrimaryQlClass() { result = "MissingExpr" } } } diff --git a/rust/ql/lib/codeql/rust/generated/MissingPat.qll b/rust/ql/lib/codeql/rust/generated/MissingPat.qll index ac1c7f349a9c..bf5edbe1685b 100644 --- a/rust/ql/lib/codeql/rust/generated/MissingPat.qll +++ b/rust/ql/lib/codeql/rust/generated/MissingPat.qll @@ -6,6 +6,7 @@ private import codeql.rust.generated.Synth private import codeql.rust.generated.Raw +import codeql.rust.elements.Missing import codeql.rust.elements.Pat /** @@ -23,7 +24,7 @@ module Generated { * INTERNAL: Do not reference the `Generated::MissingPat` class directly. * Use the subclass `MissingPat`, where the following predicates are available. */ - class MissingPat extends Synth::TMissingPat, Pat { + class MissingPat extends Synth::TMissingPat, Pat, Missing { override string getAPrimaryQlClass() { result = "MissingPat" } } } diff --git a/rust/ql/lib/codeql/rust/generated/ParentChild.qll b/rust/ql/lib/codeql/rust/generated/ParentChild.qll index f2bc4668f794..a33b11a07d70 100644 --- a/rust/ql/lib/codeql/rust/generated/ParentChild.qll +++ b/rust/ql/lib/codeql/rust/generated/ParentChild.qll @@ -23,8 +23,8 @@ private module Impl { ) } - private Element getImmediateChildOfUnimplemented( - Unimplemented e, int index, string partialPredicateCall + private Element getImmediateChildOfUnextracted( + Unextracted e, int index, string partialPredicateCall ) { exists(int b, int bElement, int n | b = 0 and @@ -51,6 +51,36 @@ private module Impl { ) } + private Element getImmediateChildOfMissing(Missing e, int index, string partialPredicateCall) { + exists(int b, int bUnextracted, int n | + b = 0 and + bUnextracted = + b + 1 + max(int i | i = -1 or exists(getImmediateChildOfUnextracted(e, i, _)) | i) and + n = bUnextracted and + ( + none() + or + result = getImmediateChildOfUnextracted(e, index - b, partialPredicateCall) + ) + ) + } + + private Element getImmediateChildOfUnimplemented( + Unimplemented e, int index, string partialPredicateCall + ) { + exists(int b, int bUnextracted, int n | + b = 0 and + bUnextracted = + b + 1 + max(int i | i = -1 or exists(getImmediateChildOfUnextracted(e, i, _)) | i) and + n = bUnextracted and + ( + none() + or + result = getImmediateChildOfUnextracted(e, index - b, partialPredicateCall) + ) + ) + } + private Element getImmediateChildOfDeclaration( Declaration e, int index, string partialPredicateCall ) { @@ -763,27 +793,33 @@ private module Impl { private Element getImmediateChildOfMissingExpr( MissingExpr e, int index, string partialPredicateCall ) { - exists(int b, int bExpr, int n | + exists(int b, int bExpr, int bMissing, int n | b = 0 and bExpr = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfExpr(e, i, _)) | i) and - n = bExpr and + bMissing = bExpr + 1 + max(int i | i = -1 or exists(getImmediateChildOfMissing(e, i, _)) | i) and + n = bMissing and ( none() or result = getImmediateChildOfExpr(e, index - b, partialPredicateCall) + or + result = getImmediateChildOfMissing(e, index - bExpr, partialPredicateCall) ) ) } private Element getImmediateChildOfMissingPat(MissingPat e, int index, string partialPredicateCall) { - exists(int b, int bPat, int n | + exists(int b, int bPat, int bMissing, int n | b = 0 and bPat = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfPat(e, i, _)) | i) and - n = bPat and + bMissing = bPat + 1 + max(int i | i = -1 or exists(getImmediateChildOfMissing(e, i, _)) | i) and + n = bMissing and ( none() or result = getImmediateChildOfPat(e, index - b, partialPredicateCall) + or + result = getImmediateChildOfMissing(e, index - bPat, partialPredicateCall) ) ) } diff --git a/rust/ql/lib/codeql/rust/generated/Raw.qll b/rust/ql/lib/codeql/rust/generated/Raw.qll index 7bd0d5058f57..ec16a9d40442 100644 --- a/rust/ql/lib/codeql/rust/generated/Raw.qll +++ b/rust/ql/lib/codeql/rust/generated/Raw.qll @@ -17,15 +17,30 @@ module Raw { /** * INTERNAL: Do not use. - * The base class for unimplemented nodes. This is used to mark nodes that are not yet extracted. + * The base class marking everything that was not properly extracted for some reason, such as: + * * syntax errors + * * insufficient context information + * * yet unimplemented parts of the extractor */ - class Unimplemented extends @unimplemented, Element { } + class Unextracted extends @unextracted, Element { } /** * INTERNAL: Do not use. */ class AstNode extends @ast_node, Locatable { } + /** + * INTERNAL: Do not use. + * The base class marking errors during parsing or resolution. + */ + class Missing extends @missing, Unextracted { } + + /** + * INTERNAL: Do not use. + * The base class for unimplemented nodes. This is used to mark nodes that are not yet extracted. + */ + class Unimplemented extends @unimplemented, Unextracted { } + /** * INTERNAL: Do not use. * The base class for declarations. @@ -903,7 +918,7 @@ module Raw { * let x = non_existing_macro!(); * ``` */ - class MissingExpr extends @missing_expr, Expr { + class MissingExpr extends @missing_expr, Expr, Missing { override string toString() { result = "MissingExpr" } } @@ -916,7 +931,7 @@ module Raw { * }; * ``` */ - class MissingPat extends @missing_pat, Pat { + class MissingPat extends @missing_pat, Pat, Missing { override string toString() { result = "MissingPat" } } diff --git a/rust/ql/lib/codeql/rust/generated/Synth.qll b/rust/ql/lib/codeql/rust/generated/Synth.qll index d3599fc21461..391d4ef6d8a8 100644 --- a/rust/ql/lib/codeql/rust/generated/Synth.qll +++ b/rust/ql/lib/codeql/rust/generated/Synth.qll @@ -308,6 +308,11 @@ module Synth { */ class TLocatable = TAstNode; + /** + * INTERNAL: Do not use. + */ + class TMissing = TMissingExpr or TMissingPat; + /** * INTERNAL: Do not use. */ @@ -321,6 +326,11 @@ module Synth { */ class TStmt = TExprStmt or TItemStmt or TLetStmt; + /** + * INTERNAL: Do not use. + */ + class TUnextracted = TMissing or TUnimplemented; + /** * INTERNAL: Do not use. */ @@ -843,7 +853,7 @@ module Synth { TElement convertElementFromRaw(Raw::Element e) { result = convertLocatableFromRaw(e) or - result = convertUnimplementedFromRaw(e) + result = convertUnextractedFromRaw(e) } /** @@ -926,6 +936,17 @@ module Synth { cached TLocatable convertLocatableFromRaw(Raw::Element e) { result = convertAstNodeFromRaw(e) } + /** + * INTERNAL: Do not use. + * Converts a raw DB element to a synthesized `TMissing`, if possible. + */ + cached + TMissing convertMissingFromRaw(Raw::Element e) { + result = convertMissingExprFromRaw(e) + or + result = convertMissingPatFromRaw(e) + } + /** * INTERNAL: Do not use. * Converts a raw DB element to a synthesized `TPat`, if possible. @@ -974,6 +995,17 @@ module Synth { result = convertLetStmtFromRaw(e) } + /** + * INTERNAL: Do not use. + * Converts a raw DB element to a synthesized `TUnextracted`, if possible. + */ + cached + TUnextracted convertUnextractedFromRaw(Raw::Element e) { + result = convertMissingFromRaw(e) + or + result = convertUnimplementedFromRaw(e) + } + /** * INTERNAL: Do not use. * Converts a raw DB element to a synthesized `TUnimplemented`, if possible. @@ -1506,7 +1538,7 @@ module Synth { Raw::Element convertElementToRaw(TElement e) { result = convertLocatableToRaw(e) or - result = convertUnimplementedToRaw(e) + result = convertUnextractedToRaw(e) } /** @@ -1589,6 +1621,17 @@ module Synth { cached Raw::Element convertLocatableToRaw(TLocatable e) { result = convertAstNodeToRaw(e) } + /** + * INTERNAL: Do not use. + * Converts a synthesized `TMissing` to a raw DB element, if possible. + */ + cached + Raw::Element convertMissingToRaw(TMissing e) { + result = convertMissingExprToRaw(e) + or + result = convertMissingPatToRaw(e) + } + /** * INTERNAL: Do not use. * Converts a synthesized `TPat` to a raw DB element, if possible. @@ -1637,6 +1680,17 @@ module Synth { result = convertLetStmtToRaw(e) } + /** + * INTERNAL: Do not use. + * Converts a synthesized `TUnextracted` to a raw DB element, if possible. + */ + cached + Raw::Element convertUnextractedToRaw(TUnextracted e) { + result = convertMissingToRaw(e) + or + result = convertUnimplementedToRaw(e) + } + /** * INTERNAL: Do not use. * Converts a synthesized `TUnimplemented` to a raw DB element, if possible. diff --git a/rust/ql/lib/codeql/rust/generated/Unimplemented.qll b/rust/ql/lib/codeql/rust/generated/Unimplemented.qll index 03c367cbcd5b..94952f78c0d2 100644 --- a/rust/ql/lib/codeql/rust/generated/Unimplemented.qll +++ b/rust/ql/lib/codeql/rust/generated/Unimplemented.qll @@ -6,7 +6,7 @@ private import codeql.rust.generated.Synth private import codeql.rust.generated.Raw -import codeql.rust.elements.Element +import codeql.rust.elements.Unextracted /** * INTERNAL: This module contains the fully generated definition of `Unimplemented` and should not @@ -18,5 +18,5 @@ module Generated { * INTERNAL: Do not reference the `Generated::Unimplemented` class directly. * Use the subclass `Unimplemented`, where the following predicates are available. */ - class Unimplemented extends Synth::TUnimplemented, Element { } + class Unimplemented extends Synth::TUnimplemented, Unextracted { } } diff --git a/rust/ql/lib/rust.dbscheme b/rust/ql/lib/rust.dbscheme index 10a0c4c37922..790bd3b73ef7 100644 --- a/rust/ql/lib/rust.dbscheme +++ b/rust/ql/lib/rust.dbscheme @@ -121,18 +121,16 @@ locatable_locations( @element = @locatable -| @unimplemented +| @unextracted ; @locatable = @ast_node ; -@unimplemented = - @generic_arg_list -| @path -| @type_ref -| @unimplemented_declaration +@unextracted = + @missing +| @unimplemented ; @ast_node = @@ -149,6 +147,18 @@ locatable_locations( | @type_ref ; +@missing = + @missing_expr +| @missing_pat +; + +@unimplemented = + @generic_arg_list +| @path +| @type_ref +| @unimplemented_declaration +; + @declaration = @function | @module diff --git a/rust/schema.py b/rust/schema.py index 1924c530cfe1..2f861ba49ac5 100644 --- a/rust/schema.py +++ b/rust/schema.py @@ -19,7 +19,6 @@ class Element: pass - @qltest.skip class Locatable(Element): pass @@ -31,7 +30,25 @@ class AstNode(Locatable): @qltest.skip -class Unimplemented(Element): +class Unextracted(Element): + """ + The base class marking everything that was not properly extracted for some reason, such as: + * syntax errors + * insufficient context information + * yet unimplemented parts of the extractor + """ + pass + + +@qltest.skip +class Missing(Unextracted): + """ + The base class marking errors during parsing or resolution. + """ + + +@qltest.skip +class Unimplemented(Unextracted): """ The base class for unimplemented nodes. This is used to mark nodes that are not yet extracted. """ @@ -156,7 +173,7 @@ class Function(Declaration): @rust.doc_test_signature("() -> ()") -class MissingExpr(Expr): +class MissingExpr(Expr, Missing): """ A missing expression, used as a placeholder for incomplete syntax. @@ -821,7 +838,7 @@ class ItemStmt(Stmt): @rust.doc_test_signature("() -> ()") -class MissingPat(Pat): +class MissingPat(Pat, Missing): """ A missing pattern, used as a place holder for incomplete syntax. ``` @@ -984,7 +1001,7 @@ class IdentPat(Pat): class TupleStructPat(Pat): """ A tuple struct pattern. For example: - ``` + ``` match x { Tuple("a", 1, 2, 3) => "great", Tuple(.., 3) => "fine", From 64f77051bd369a3366b17e222dbe0d9caef67e9a Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 16 Sep 2024 16:02:59 +0200 Subject: [PATCH 2/2] Rust: commit forgotten new files --- rust/ql/lib/codeql/rust/elements/Missing.qll | 11 ++++++++ .../lib/codeql/rust/elements/Unextracted.qll | 14 +++++++++++ rust/ql/lib/codeql/rust/generated/Missing.qll | 22 ++++++++++++++++ .../lib/codeql/rust/generated/Unextracted.qll | 25 +++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 rust/ql/lib/codeql/rust/elements/Missing.qll create mode 100644 rust/ql/lib/codeql/rust/elements/Unextracted.qll create mode 100644 rust/ql/lib/codeql/rust/generated/Missing.qll create mode 100644 rust/ql/lib/codeql/rust/generated/Unextracted.qll diff --git a/rust/ql/lib/codeql/rust/elements/Missing.qll b/rust/ql/lib/codeql/rust/elements/Missing.qll new file mode 100644 index 000000000000..a6c3ff917441 --- /dev/null +++ b/rust/ql/lib/codeql/rust/elements/Missing.qll @@ -0,0 +1,11 @@ +// generated by codegen, remove this comment if you wish to edit this file +/** + * This module provides a hand-modifiable wrapper around the generated class `Missing`. + */ + +private import codeql.rust.generated.Missing + +/** + * The base class marking errors during parsing or resolution. + */ +class Missing extends Generated::Missing { } diff --git a/rust/ql/lib/codeql/rust/elements/Unextracted.qll b/rust/ql/lib/codeql/rust/elements/Unextracted.qll new file mode 100644 index 000000000000..df568d6328f7 --- /dev/null +++ b/rust/ql/lib/codeql/rust/elements/Unextracted.qll @@ -0,0 +1,14 @@ +// generated by codegen, remove this comment if you wish to edit this file +/** + * This module provides a hand-modifiable wrapper around the generated class `Unextracted`. + */ + +private import codeql.rust.generated.Unextracted + +/** + * The base class marking everything that was not properly extracted for some reason, such as: + * * syntax errors + * * insufficient context information + * * yet unimplemented parts of the extractor + */ +class Unextracted extends Generated::Unextracted { } diff --git a/rust/ql/lib/codeql/rust/generated/Missing.qll b/rust/ql/lib/codeql/rust/generated/Missing.qll new file mode 100644 index 000000000000..11aba96ac14d --- /dev/null +++ b/rust/ql/lib/codeql/rust/generated/Missing.qll @@ -0,0 +1,22 @@ +// generated by codegen +/** + * This module provides the generated definition of `Missing`. + * INTERNAL: Do not import directly. + */ + +private import codeql.rust.generated.Synth +private import codeql.rust.generated.Raw +import codeql.rust.elements.Unextracted + +/** + * INTERNAL: This module contains the fully generated definition of `Missing` and should not + * be referenced directly. + */ +module Generated { + /** + * The base class marking errors during parsing or resolution. + * INTERNAL: Do not reference the `Generated::Missing` class directly. + * Use the subclass `Missing`, where the following predicates are available. + */ + class Missing extends Synth::TMissing, Unextracted { } +} diff --git a/rust/ql/lib/codeql/rust/generated/Unextracted.qll b/rust/ql/lib/codeql/rust/generated/Unextracted.qll new file mode 100644 index 000000000000..0c6fa1acb53c --- /dev/null +++ b/rust/ql/lib/codeql/rust/generated/Unextracted.qll @@ -0,0 +1,25 @@ +// generated by codegen +/** + * This module provides the generated definition of `Unextracted`. + * INTERNAL: Do not import directly. + */ + +private import codeql.rust.generated.Synth +private import codeql.rust.generated.Raw +import codeql.rust.elements.Element + +/** + * INTERNAL: This module contains the fully generated definition of `Unextracted` and should not + * be referenced directly. + */ +module Generated { + /** + * The base class marking everything that was not properly extracted for some reason, such as: + * * syntax errors + * * insufficient context information + * * yet unimplemented parts of the extractor + * INTERNAL: Do not reference the `Generated::Unextracted` class directly. + * Use the subclass `Unextracted`, where the following predicates are available. + */ + class Unextracted extends Synth::TUnextracted, Element { } +}