[SR-2209] Make a real "AccessScope" type and use it in access checking #44816
Labels
compiler
The Swift compiler in itself
diagnostics QoI
Bug: Diagnostics Quality of Implementation
good first issue
Good for newcomers
improvement
Additional Detail from JIRA
md5: bc3d512877f80019fe70957946ca4ef4
relates to:
Issue Description:
To implement Swift 3's
private
I introduced a new concept called "access scope", which is used to check if it's okay to use a particular declaration. This is described pretty well in the commit message for 758cf64; the primary entry point is ValueDecl::getFormalAccessScope.Currently, this function just returns a DeclContext like any other. There are two problems with this: (1) this isn't just any DeclContext, and it's often passed as an argument next to other DeclContexts (usually the use site), and (2) it erases the distinction between
private
andfileprivate
for top-level declarations, which leads to diagnostics claiming something isfileprivate
even though the user has writtenprivate
.Instead, we should create a new type
AccessScope
which just wraps a DeclContext, along with a bit saying whether a top-level DeclContext should be treated asprivate
rather thanfileprivate
.The steps to do this are roughly:
1. Make a new AccessScope type that just wraps a plain DeclContext.
2. Propagate it into all uses of
ValueDecl::getFormalAccessScope
, transitively.3. Turn all operations that combine access scopes into methods on AccessScope.
4. Add the "private" flag, using PointerIntPair as shown above to keep the overhead low.
5. Update or replace
accessibilityFromScopeForDiagnostics
in TypeCheckDecl.cpp to check the "private" flag.I've tagged this as "StarterBug" because even though it involves a bit of spelunking through the codebase, each of these steps should be fairly obvious (i.e. there's not much design work), and you still get diagnostic improvements out at the end. The separate steps can also be reviewed separately, following Swift's incremental development model.
Please feel free to ask me for help on swift-dev!
The text was updated successfully, but these errors were encountered: