-
Notifications
You must be signed in to change notification settings - Fork 8
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
add first batch of visibilty rules and simple test #1745
add first batch of visibilty rules and simple test #1745
Conversation
8748d84
to
4b1e1b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. Particularly like that you did a big effort to check many special cases of visibility.
Just some minor comments suggestions from me.
src/dev/flang/ast/AbstractType.java
Outdated
private Set<AbstractType> usedTypes() | ||
{ | ||
var result = new TreeSet<AbstractType>(); | ||
usedTypes(result); | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally, I prefer traversing on demand. There is a method applyToGenericsAndOuter
that visits all used types (which is maybe too much), but you could add a variant applyToXYZ
.
Here, I think all you need to check is the direct type parameters (see comments below), which are directly available with `generics()´.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now added an abstract method abstract void usedFeatures(Set<AbstractFeature> s)
to AbstractType
which collects all the features the type uses/needs into a set. These can then be checked for sufficient visibility.
3708458
to
92af122
Compare
#1776 should be merge first |
81c956f
to
2ebfb74
Compare
visibility of feature of call is now compared to features visibility having the pre-condition.
print which used type/generic is not visible enough.
2ebfb74
to
a0488fd
Compare
a0488fd
to
265a36c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Just some minor restructuring requests and a NYI that can be removed.
src/dev/flang/fe/SourceModule.java
Outdated
@@ -1023,7 +1029,10 @@ public List<FeatureAndOuter> lookup(AbstractFeature outer, String name, Stmnt us | |||
} | |||
} | |||
|
|||
for (var e : fs.entrySet()) | |||
for (var e : fs.entrySet() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the NYI-Comment in line 1011: NYI: AND curOuter loaded by this module
, which is true since curOuter instanceof Feature
was checked.
src/dev/flang/fe/SourceModule.java
Outdated
.filter(fn -> use == null || featureVisible(use.pos()._sourceFile, fn.getValue())) | ||
.collect(List.collector())) | ||
{ | ||
var v = e.getValue(); | ||
if (!v.isField() || !foundFieldInScope) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the code pattern a bit strange here, basically you do
for (var e : fs.filter(x -> cond1(x)))
{
if (cond2(e))
{
result.add(new ..);
]
}
which is equivalent to
for (var e : fs)
{
if (cond1(e) && cond2(e))
{
result.add(new ..);
]
}
src/dev/flang/fe/SourceModule.java
Outdated
var fs = lookup(outer, name, null, traverseOuter) | ||
.stream() | ||
.filter(fo -> typeVisible(pos._sourceFile, fo._feature)) | ||
.collect(Collectors.toList()); | ||
for (var fo : fs) | ||
{ | ||
var f = fo._feature; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, maybe add an if (typeVisible(...))
in the loop instead of using the stream.
* | ||
* @return this type and any of its generics that have more restrictive visibility than `v`. | ||
*/ | ||
public Set<AbstractFeature> moreRestrictiveVisibility(Visi v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ok for now, but think it might be better to use a visitor similar to applyToGenericsAndOuter
eventually.
*/ | ||
protected void usedFeatures(Set<AbstractFeature> s) | ||
{ | ||
var f = featureOfType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This currently does not touch the outer features. This means that for a type like (x T).y U
the visibility of x
and T
will be ignored, which is probably wrong.
But this can be fixed later.
All the weird/tricky cases regarding visibility seem to be related to inheritance.
Examples:
lets say we inherit from feature in another file that inherits from feature in current file.
should the inherited private features be visible?
We have this feature and return its supertype
Any
somewhere. Currently callingas_string
results inmod
even though the redefinition feature might not even be visible.Reusing names for fields (see commented out
say b.get_field
) is not yet working. crashes: