Skip to content
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

Merged
merged 12 commits into from Aug 4, 2023

Conversation

michaellilltokiwa
Copy link
Member

@michaellilltokiwa michaellilltokiwa commented Jul 18, 2023

All the weird/tricky cases regarding visibility seem to be related to inheritance.
Examples:

  1. lets say we inherit from feature in another file that inherits from feature in current file.
    should the inherited private features be visible?

  2. We have this feature and return its supertype Any somewhere. Currently calling as_string results in mod even though the redefinition feature might not even be visible.

private mod : Any is
  private redef as_string is
   "mod"
  1. what to do with cases like this?:
module feat : Sequence i_am_private is
  1. I'm all but certain to have thought of all possible cases...

Reusing names for fields (see commented out say b.get_field) is not yet working. crashes:

error 2: java.lang.Error: require-condition3 failed: dev.flang.be.interpreter.Layout:offset:246
	at dev.flang.util.ANY.require(ANY.java:113)
	at dev.flang.be.interpreter.Layout.offset(Layout.java:246)
error 1: java.lang.Error: Value.setField for 'b.field' called on class UNIT (class dev.flang.fuir.analysis.dfa.Value$2), expected class dev.flang.fuir.analysis.dfa.Instance

src/dev/flang/ast/AbstractType.java Outdated Show resolved Hide resolved
src/dev/flang/parser/Parser.java Show resolved Hide resolved
src/dev/flang/ast/AstErrors.java Outdated Show resolved Hide resolved
src/dev/flang/ast/AstErrors.java Outdated Show resolved Hide resolved
src/dev/flang/ast/AstErrors.java Outdated Show resolved Hide resolved
src/dev/flang/ast/AstErrors.java Outdated Show resolved Hide resolved
src/dev/flang/ast/AstErrors.java Show resolved Hide resolved
src/dev/flang/fe/Module.java Outdated Show resolved Hide resolved
src/dev/flang/fe/Module.java Show resolved Hide resolved
src/dev/flang/fe/SourceModule.java Show resolved Hide resolved
@michaellilltokiwa michaellilltokiwa marked this pull request as ready for review July 20, 2023 13:32
Copy link
Member

@fridis fridis left a 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 Show resolved Hide resolved
Comment on lines 1575 to 1698
private Set<AbstractType> usedTypes()
{
var result = new TreeSet<AbstractType>();
usedTypes(result);
return result;
}
Copy link
Member

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()´.

Copy link
Member Author

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.

src/dev/flang/ast/AbstractType.java Outdated Show resolved Hide resolved
src/dev/flang/ast/AbstractType.java Outdated Show resolved Hide resolved
src/dev/flang/ast/Visi.java Outdated Show resolved Hide resolved
src/dev/flang/fe/Module.java Outdated Show resolved Hide resolved
src/dev/flang/fe/Module.java Show resolved Hide resolved
src/dev/flang/fe/SourceModule.java Outdated Show resolved Hide resolved
src/dev/flang/fe/SourceModule.java Outdated Show resolved Hide resolved
michaellilltokiwa added a commit to michaellilltokiwa/fuzion that referenced this pull request Jul 28, 2023
@michaellilltokiwa michaellilltokiwa marked this pull request as draft July 28, 2023 09:26
@michaellilltokiwa
Copy link
Member Author

#1776 should be merge first

michaellilltokiwa added a commit to michaellilltokiwa/fuzion that referenced this pull request Jul 28, 2023
michaellilltokiwa added a commit to michaellilltokiwa/fuzion that referenced this pull request Jul 31, 2023
Copy link
Member

@fridis fridis left a 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.

@@ -1023,7 +1029,10 @@ public List<FeatureAndOuter> lookup(AbstractFeature outer, String name, Stmnt us
}
}

for (var e : fs.entrySet())
for (var e : fs.entrySet()
Copy link
Member

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.

Comment on lines 1034 to 1038
.filter(fn -> use == null || featureVisible(use.pos()._sourceFile, fn.getValue()))
.collect(List.collector()))
{
var v = e.getValue();
if (!v.isField() || !foundFieldInScope)
Copy link
Member

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 ..);
        ]
    }

Comment on lines 1122 to 1128
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;
Copy link
Member

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)
Copy link
Member

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();
Copy link
Member

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.

@fridis fridis merged commit 8b28373 into tokiwa-software:main Aug 4, 2023
4 checks passed
@michaellilltokiwa michaellilltokiwa deleted the visibility_rules branch October 11, 2023 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants