Skip to content

Rust: emit Const bodies in library mode #19651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: redsun82/rust-has-implementation
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/ast-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fn get_additional_fields(node: &AstNodeSrc) -> Vec<FieldInfo> {
"FormatArgsExpr" => vec![FieldInfo::list("args", "FormatArgsArg")],
"ArgList" => vec![FieldInfo::list("args", "Expr")],
"Fn" => vec![FieldInfo::body("body", "BlockExpr")],
"Const" => vec![FieldInfo::body("body", "Expr")],
"Const" => vec![FieldInfo::optional("body", "Expr")],
"Static" => vec![FieldInfo::body("body", "Expr")],
"Param" => vec![FieldInfo::body("pat", "Pat")],
"ClosureExpr" => vec![FieldInfo::optional("body", "Expr")],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2816,11 +2816,6 @@ const_visibilities(
int visibility: @visibility ref
);

#keyset[id]
const_has_implementation(
int id: @const ref
);

enums(
unique int id: @enum
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
description: Remove `function_has_implementation` table
compatibility: full

function_has_implementation.rel: delete

This file was deleted.

2 changes: 1 addition & 1 deletion rust/extractor/src/generated/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions rust/extractor/src/generated/top.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions rust/extractor/src/translate/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ macro_rules! post_emit {
(PathSegment, $self:ident, $node:ident, $label:ident) => {
$self.extract_types_from_path_segment($node, $label.into());
};
(Const, $self:ident, $node:ident, $label:ident) => {
$self.emit_const_has_implementation($node, $label);
};
($($_:tt)*) => {};
}

Expand Down Expand Up @@ -775,14 +772,4 @@ impl<'a> Translator<'a> {
generated::Function::emit_has_implementation(label, &mut self.trap.writer);
}
}

pub(crate) fn emit_const_has_implementation(
&mut self,
node: &ast::Const,
label: Label<generated::Const>,
) {
if node.body().is_some() {
generated::Const::emit_has_implementation(label, &mut self.trap.writer);
}
}
}
6 changes: 1 addition & 5 deletions rust/extractor/src/translate/generated.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions rust/ql/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions rust/ql/lib/codeql/rust/elements/internal/generated/Const.qll

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions rust/ql/lib/rust.dbscheme
Original file line number Diff line number Diff line change
Expand Up @@ -2816,11 +2816,6 @@ const_visibilities(
int visibility: @visibility ref
);

#keyset[id]
const_has_implementation(
int id: @const ref
);

enums(
unique int id: @enum
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2816,11 +2816,6 @@ const_visibilities(
int visibility: @visibility ref
);

#keyset[id]
const_has_implementation(
int id: @const ref
);

enums(
unique int id: @enum
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
description: Add `function_has_implementation` and `const_has_implementation` tables
description: Add `function_has_implementation` table
compatibility: backwards

function_has_implementation.rel: run upgrade.ql new_function_has_implementation
const_has_implementation.rel: run upgrade.ql new_const_has_implementation
function_has_implementation.rel: reorder function_bodies.rel (@function id, @block_expr body) id

This file was deleted.

9 changes: 3 additions & 6 deletions rust/ql/test/extractor-tests/generated/Const/Const.ql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions rust/schema/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,10 +951,6 @@ class _:
todo!()
```
"""
has_implementation: predicate | doc("this constant has an implementation") | desc("""
This is the same as `hasBody` for source code, but for library code (for which we always skip
the body), this will hold when the body was present in the original code.
""") | rust.detach


@annotate(ConstArg)
Expand Down