Skip to content

Commit 8259482

Browse files
authored
refactor builtin types in binder (#1821)
Small rename for the public API: - renames the public `PublicBuiltin` type to just `Builtin`, as it is used in the public API, and the "Public" prefix is redundant. - renames the internal `Builtin` type to `InternalBuiltin`, to make it clear that this should not be leaked to the public API.
1 parent 227d4da commit 8259482

10 files changed

Lines changed: 693 additions & 654 deletions

File tree

crates/solidity-v2/outputs/cargo/semantic/generated/public_api.txt

Lines changed: 175 additions & 175 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/solidity-v2/outputs/cargo/semantic/src/binder/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet, VecDeque};
22

33
use slang_solidity_v2_common::nodes::NodeId;
44

5-
use super::built_ins::BuiltIn;
5+
use super::built_ins::InternalBuiltIn;
66
use super::types::{Type, TypeId};
77

88
mod definitions;
@@ -58,7 +58,7 @@ pub enum Typing {
5858
/// resolves to `Resolution::BuiltIn(Addmod)` and will type to
5959
/// `Typing::BuiltIn(Addmod)` which in turn will type to the `uint256` type
6060
/// when evaluated in the context of a function call.
61-
BuiltIn(BuiltIn),
61+
BuiltIn(InternalBuiltIn),
6262
/// A special typing that's used as the result of applying the `new`
6363
/// operator, and will type to a contract reference when evaluated as a
6464
/// function call.

crates/solidity-v2/outputs/cargo/semantic/src/binder/references.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use slang_solidity_v2_common::nodes::NodeId;
22
use slang_solidity_v2_ir::ir;
33

4-
use crate::built_ins::BuiltIn;
4+
use crate::built_ins::InternalBuiltIn;
55

66
//////////////////////////////////////////////////////////////////////////////
77
// References
@@ -30,7 +30,7 @@ pub enum Resolution {
3030
/// The symbol refers to a Solidity built-in of some kind. The possible
3131
/// variants are encoded in an enum and the behaviour of each is encoded in
3232
/// the `built_ins.rs` module.
33-
BuiltIn(BuiltIn),
33+
BuiltIn(InternalBuiltIn),
3434
}
3535

3636
impl Reference {
@@ -106,8 +106,8 @@ impl From<Vec<NodeId>> for Resolution {
106106
}
107107
}
108108

109-
impl From<Option<BuiltIn>> for Resolution {
110-
fn from(value: Option<BuiltIn>) -> Self {
109+
impl From<Option<InternalBuiltIn>> for Resolution {
110+
fn from(value: Option<InternalBuiltIn>) -> Self {
111111
if let Some(built_in) = value {
112112
Self::BuiltIn(built_in)
113113
} else {

crates/solidity-v2/outputs/cargo/semantic/src/built_ins/internal.generated.rs

Lines changed: 161 additions & 161 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/solidity-v2/outputs/cargo/semantic/src/built_ins/internal.rs.jinja2

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use slang_solidity_v2_common::versions::{LanguageVersion, LanguageVersionSpecifier};
2-
use slang_solidity_v2_common::built_ins::BuiltIn as PublicBuiltIn;
2+
use slang_solidity_v2_common::built_ins::BuiltIn;
33
use slang_solidity_v2_common::nodes::NodeId;
44
use crate::types::TypeId;
55

@@ -9,7 +9,7 @@ use crate::types::TypeId;
99
/// `.push()` or `AraryPush` needs to carry the type of the original array to
1010
/// correctly resolve the type in a function call context.
1111
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
12-
pub enum BuiltIn {
12+
pub enum InternalBuiltIn {
1313
{% for context in model.language.built_ins -%}
1414
{% for scope in context.scopes -%}
1515
{% for definition in scope.definitions %}
@@ -22,17 +22,17 @@ pub enum BuiltIn {
2222
{% endfor %}
2323
}
2424

25-
impl BuiltIn {
25+
impl InternalBuiltIn {
2626
/// Converts this internal built-in representation to the public enum type
2727
/// defined in the `common` crate.
2828
#[allow(clippy::too_many_lines)]
29-
pub fn to_public(&self) -> PublicBuiltIn {
29+
pub fn to_public(&self) -> BuiltIn {
3030
match self {
3131
{% for context in model.language.built_ins -%}
3232
{% for scope in context.scopes -%}
3333
{% for definition in scope.definitions %}
3434
Self::{{ definition.name }}{% if definition.internal_parameter %}(_){% endif %} =>
35-
PublicBuiltIn::{{ definition.name }},
35+
BuiltIn::{{ definition.name }},
3636
{%- endfor %}
3737
{% endfor -%}
3838
{% endfor %}

crates/solidity-v2/outputs/cargo/semantic/src/built_ins/mod.rs

Lines changed: 333 additions & 296 deletions
Large diffs are not rendered by default.

crates/solidity-v2/outputs/cargo/semantic/src/passes/p3_type_definitions/evaluator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use ruint::aliases::U256;
33
use sha3::{Digest, Keccak256};
44
use slang_solidity_v2_ir::ir;
55

6-
use crate::built_ins::BuiltIn;
6+
use crate::built_ins::InternalBuiltIn;
77
use crate::types::{literals, Number};
88

99
pub(crate) fn evaluate_compile_time_usize_constant<Scope>(
@@ -42,7 +42,7 @@ pub(crate) enum ComptimeResolution<Scope> {
4242
value: ir::Expression,
4343
target_scope: Scope,
4444
},
45-
BuiltIn(BuiltIn),
45+
BuiltIn(InternalBuiltIn),
4646
}
4747

4848
pub(crate) trait ConstantIdentifierResolver<Scope> {
@@ -257,7 +257,7 @@ impl<Scope> CompileConstantEvaluator<'_, Scope> {
257257
.identifier_resolver
258258
.resolve_identifier_in_scope(operand.unparse(), scope);
259259
match resolution {
260-
ComptimeResolution::BuiltIn(BuiltIn::Erc7201) => {
260+
ComptimeResolution::BuiltIn(InternalBuiltIn::Erc7201) => {
261261
self.evaluate_erc7201_built_in_call(&call.arguments)
262262
}
263263
_ => None,
@@ -377,7 +377,7 @@ mod tests {
377377
target_scope: target_scope.clone(),
378378
}
379379
} else if self.recognise_erc7201 && identifier == "erc7201" {
380-
ComptimeResolution::BuiltIn(BuiltIn::Erc7201)
380+
ComptimeResolution::BuiltIn(InternalBuiltIn::Erc7201)
381381
} else {
382382
ComptimeResolution::Unresolved
383383
}

crates/solidity-v2/outputs/cargo/semantic/src/passes/p3_type_definitions/visitor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use slang_solidity_v2_ir::ir::visitor::Visitor;
88
use super::evaluator::evaluate_compile_time_integer_constant;
99
use super::Pass;
1010
use crate::binder::{Definition, Reference, Resolution, Scope, Typing, UsingDirective};
11-
use crate::built_ins::BuiltIn;
11+
use crate::built_ins::InternalBuiltIn;
1212
use crate::types::{ContractType, DataLocation, EnumType, InterfaceType, LibraryType, Type};
1313

1414
impl Visitor for Pass<'_> {
@@ -437,7 +437,7 @@ impl Visitor for Pass<'_> {
437437
fn enter_catch_clause_error(&mut self, node: &ir::CatchClauseError) -> bool {
438438
if let Some(name) = &node.name {
439439
let resolution = match name.unparse() {
440-
"Error" | "Panic" => Resolution::BuiltIn(BuiltIn::ErrorOrPanic),
440+
"Error" | "Panic" => Resolution::BuiltIn(InternalBuiltIn::ErrorOrPanic),
441441
_ => Resolution::Unresolved,
442442
};
443443
let reference = Reference::new(Arc::clone(name), resolution);
@@ -455,7 +455,7 @@ impl Visitor for Pass<'_> {
455455
fn leave_type_expression(&mut self, node: &ir::TypeExpression) {
456456
let type_id = self.resolve_type_name(&node.type_name, Some(DataLocation::Memory));
457457
let typing = type_id.map_or(Typing::Unresolved, |type_id| {
458-
Typing::BuiltIn(BuiltIn::Type(type_id))
458+
Typing::BuiltIn(InternalBuiltIn::Type(type_id))
459459
});
460460
self.binder.set_node_typing(node.id(), typing);
461461
}

crates/solidity-v2/outputs/cargo/semantic/src/passes/p4_resolve_references/typing.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use slang_solidity_v2_ir::ir;
44

55
use super::Pass;
66
use crate::binder::{Definition, Resolution, Typing};
7-
use crate::built_ins::BuiltIn;
7+
use crate::built_ins::InternalBuiltIn;
88
use crate::passes::common::node_id_for_expression_typing;
99
use crate::types::{
1010
literals, AddressType, ContractType, DataLocation, EnumType, FixedSizeArrayType, FunctionType,
@@ -438,7 +438,9 @@ impl Pass<'_> {
438438
// Special case: for `abi.decode` we need to register the types
439439
// given as the second argument and we need a mutable `TypeRegistry`
440440
// for that.
441-
Typing::BuiltIn(BuiltIn::AbiDecode) => self.typing_of_abi_decode(&argument_typings),
441+
Typing::BuiltIn(InternalBuiltIn::AbiDecode) => {
442+
self.typing_of_abi_decode(&argument_typings)
443+
}
442444
Typing::BuiltIn(built_in) => self
443445
.built_ins_resolver()
444446
.typing_of_function_call(&built_in, &argument_typings),

crates/solidity-v2/outputs/cargo/semantic/src/passes/p4_resolve_references/visitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use slang_solidity_v2_ir::ir::visitor::Visitor;
55

66
use super::Pass;
77
use crate::binder::{Reference, Resolution, Typing};
8-
use crate::built_ins::BuiltIn;
8+
use crate::built_ins::InternalBuiltIn;
99
use crate::passes::common::node_id_for_string_expression_typing;
1010
use crate::types::{
1111
ArrayType, DataLocation, FixedSizeArrayType, MappingType, Number, TupleType, Type,
@@ -119,7 +119,7 @@ impl Visitor for Pass<'_> {
119119
if let ir::Expression::Identifier(identifier) = node {
120120
let symbol = identifier.unparse();
121121
let resolution = if symbol == "_" && self.is_in_modifier_scope() {
122-
Resolution::BuiltIn(BuiltIn::ModifierUnderscore)
122+
Resolution::BuiltIn(InternalBuiltIn::ModifierUnderscore)
123123
} else {
124124
let scope_id = self.current_scope_id();
125125
self.filter_overriden_definitions(self.resolve_symbol_in_scope(scope_id, symbol))

0 commit comments

Comments
 (0)