Skip to content

Commit 083fbce

Browse files
committed
Rework visibility level while doing visibility checking.
1 parent 1f7b6f4 commit 083fbce

File tree

10 files changed

+136
-25
lines changed

10 files changed

+136
-25
lines changed

sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ impl ty::TyExpression {
12591259
&storage_key_ident.into(),
12601260
None,
12611261
VisibilityCheck::No,
1262+
Visibility::Public,
12621263
)?;
12631264

12641265
let storage_key_struct_decl_id = storage_key_decl

sway-core/src/semantic_analysis/symbol_resolve_context.rs

+18
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub struct SymbolResolveContext<'a> {
4343
///
4444
/// This is `Disallow` everywhere except while checking type parameters bounds in struct instantiation.
4545
generic_shadowing_mode: GenericShadowingMode,
46+
/// Visibility checking level for the current scope.
47+
visibility_level: Visibility,
4648
}
4749

4850
impl<'a> SymbolResolveContext<'a> {
@@ -57,6 +59,7 @@ impl<'a> SymbolResolveContext<'a> {
5759
self_type: None,
5860
const_shadowing_mode: ConstShadowingMode::ItemStyle,
5961
generic_shadowing_mode: GenericShadowingMode::Disallow,
62+
visibility_level: Visibility::Public,
6063
}
6164
}
6265

@@ -75,6 +78,7 @@ impl<'a> SymbolResolveContext<'a> {
7578
self_type: self.self_type,
7679
const_shadowing_mode: self.const_shadowing_mode,
7780
generic_shadowing_mode: self.generic_shadowing_mode,
81+
visibility_level: Visibility::Public,
7882
}
7983
}
8084

@@ -158,6 +162,15 @@ impl<'a> SymbolResolveContext<'a> {
158162
}
159163
}
160164

165+
/// Map this `SymbolResolveContext` instance to a new one with the given visibility level.
166+
#[allow(unused)]
167+
pub(crate) fn with_visibility_level(self, visibility_level: Visibility) -> Self {
168+
Self {
169+
visibility_level,
170+
..self
171+
}
172+
}
173+
161174
// A set of accessor methods. We do this rather than making the fields `pub` in order to ensure
162175
// that these are only updated via the `with_*` methods that produce a new `SymbolResolveContext`.
163176
#[allow(unused)]
@@ -175,6 +188,10 @@ impl<'a> SymbolResolveContext<'a> {
175188
self.generic_shadowing_mode
176189
}
177190

191+
pub(crate) fn visibility_level(&self) -> Visibility {
192+
self.visibility_level
193+
}
194+
178195
/// Get the engines needed for engine threading.
179196
pub(crate) fn engines(&self) -> &'a Engines {
180197
self.engines
@@ -194,6 +211,7 @@ impl<'a> SymbolResolveContext<'a> {
194211
call_path,
195212
self.self_type(),
196213
VisibilityCheck::Yes,
214+
self.visibility_level(),
197215
)
198216
}
199217
}

sway-core/src/semantic_analysis/type_check_context.rs

+17
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ pub struct TypeCheckContext<'a> {
111111
// In some nested places of the first pass we want to disable the first pass optimizations
112112
// To disable those optimizations we can set this to false.
113113
code_block_first_pass: bool,
114+
115+
/// Visibility checking level for the current scope.
116+
visibility_level: Visibility,
114117
}
115118

116119
impl<'a> TypeCheckContext<'a> {
@@ -140,6 +143,7 @@ impl<'a> TypeCheckContext<'a> {
140143
experimental,
141144
collecting_unifications: false,
142145
code_block_first_pass: false,
146+
visibility_level: Visibility::Public,
143147
}
144148
}
145149

@@ -184,6 +188,7 @@ impl<'a> TypeCheckContext<'a> {
184188
experimental,
185189
collecting_unifications: false,
186190
code_block_first_pass: false,
191+
visibility_level: Visibility::Public,
187192
}
188193
}
189194

@@ -215,6 +220,7 @@ impl<'a> TypeCheckContext<'a> {
215220
experimental: self.experimental,
216221
collecting_unifications: self.collecting_unifications,
217222
code_block_first_pass: self.code_block_first_pass,
223+
visibility_level: self.visibility_level,
218224
}
219225
}
220226

@@ -265,6 +271,7 @@ impl<'a> TypeCheckContext<'a> {
265271
experimental: ctx.experimental,
266272
collecting_unifications: ctx.collecting_unifications,
267273
code_block_first_pass: ctx.code_block_first_pass,
274+
visibility_level: ctx.visibility_level,
268275
};
269276
with_scoped_ctx(&mut ctx)
270277
},
@@ -518,6 +525,10 @@ impl<'a> TypeCheckContext<'a> {
518525
self.code_block_first_pass
519526
}
520527

528+
pub(crate) fn visibility_level(&self) -> Visibility {
529+
self.visibility_level
530+
}
531+
521532
/// Get the engines needed for engine threading.
522533
pub(crate) fn engines(&self) -> &'a Engines {
523534
self.engines
@@ -625,6 +636,7 @@ impl<'a> TypeCheckContext<'a> {
625636
self.self_type(),
626637
&self.subst_ctx(),
627638
VisibilityCheck::Yes,
639+
Visibility::Public,
628640
)
629641
}
630642

@@ -642,6 +654,7 @@ impl<'a> TypeCheckContext<'a> {
642654
self.self_type(),
643655
&self.subst_ctx(),
644656
VisibilityCheck::Yes,
657+
self.visibility_level(),
645658
)
646659
.map(|d| d.expect_typed())
647660
}
@@ -660,6 +673,7 @@ impl<'a> TypeCheckContext<'a> {
660673
&symbol.clone().into(),
661674
self.self_type(),
662675
VisibilityCheck::No,
676+
Visibility::Public,
663677
)
664678
.map(|d| d.expect_typed())
665679
}
@@ -678,6 +692,7 @@ impl<'a> TypeCheckContext<'a> {
678692
call_path,
679693
self.self_type(),
680694
VisibilityCheck::Yes,
695+
self.visibility_level(),
681696
)
682697
.map(|d| d.expect_typed())
683698
}
@@ -696,6 +711,7 @@ impl<'a> TypeCheckContext<'a> {
696711
call_path,
697712
self.self_type(),
698713
VisibilityCheck::No,
714+
self.visibility_level(),
699715
)
700716
.map(|d| d.expect_typed())
701717
}
@@ -740,6 +756,7 @@ impl<'a> TypeCheckContext<'a> {
740756
self.self_type(),
741757
&self.subst_ctx(),
742758
VisibilityCheck::Yes,
759+
Visibility::Public,
743760
)
744761
.unwrap_or_else(|err| type_engine.id_of_error_recovery(err));
745762

0 commit comments

Comments
 (0)