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

feat!: New behavior for opened import where module contains homonymous top-level declaration #2355

Merged
merged 13 commits into from
Sep 21, 2022

Commits on Jul 1, 2022

  1. Clean up old code

    RustanLeino committed Jul 1, 2022
    Configuration menu
    Copy the full SHA
    444df54 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    415f97e View commit details
    Browse the repository at this point in the history
  3. feat!: Let M refer to M.M in opened import

    For `import opened M` where `M` is a module that declares a top-level `M`, let `M` in the importer refer to that top-level `M` instead of referring to the module `M`.
    
    Fixes dafny-lang#1996
    RustanLeino committed Jul 1, 2022
    Configuration menu
    Copy the full SHA
    aedc64e View commit details
    Browse the repository at this point in the history
  4. Add release notes

    RustanLeino committed Jul 1, 2022
    Configuration menu
    Copy the full SHA
    bf0eddd View commit details
    Browse the repository at this point in the history

Commits on Sep 13, 2022

  1. Merge branch 'master' into issue-1996

    # Conflicts:
    #	RELEASE_NOTES.md
    RustanLeino committed Sep 13, 2022
    Configuration menu
    Copy the full SHA
    bef8d31 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    894acaf View commit details
    Browse the repository at this point in the history

Commits on Sep 15, 2022

  1. Configuration menu
    Copy the full SHA
    397884f View commit details
    Browse the repository at this point in the history

Commits on Sep 16, 2022

  1. Raise resolution errors instead of silently changing behavior

    The resolution change introduced by the previous commit silently changes the
    meaning of existing Dafny programs.  This commit does its best to detect these
    cases and raise resolution errors instead.
    
    To illustrate the technique, consider the following example:
    
        module Option {
          static const a := 1
          datatype Option = … { static const a := 2 }
        }
    
        module X {
          import opened Option
          method M() { print Option.A; }
        }
    
    This program printed 1 in previous versions of Dafny.  It would print 2 with the
    new resolution strategy introduced in this commit.  To avoid that, the program
    is rejected instead.
    
    To do so, we keep track of shadowing in a separate table:
    
    * Source/DafnyCore/AST/TopLevelDeclarations.cs (ModuleSignature): Add a new
    field `ShadowedImportedModules`.
    * Source/DafnyCore/Resolver.cs (ResolveOpenedImports): Keep track of
    shadowed modules.
    
    This table is used in `ResolveDotSuffix`:
    
    * Source/DafnyCore/Resolver.cs (ResolveNameSegment): Return name of shadowed
    module, if any, as an out parameter
    (ResolveDotSuffix): Before returning, make sure that the same name could not
    have been resolved in the parent module.
    
    The check is performed in `CheckForAmbiguityInShadowedImportedModule`, which
    runs a simplified version of resolution of a name in a module:
    
    * Source/DafnyCore/Resolver.cs (CheckForAmbiguityInShadowedImportedModule):
    Error out if the shadowed module contains a conflicting name (a name that would
    previously would have been instead of the one that the new resolution algorithm
    picks).
    (NameConflictsWithModuleContents): Determine whether a conflicting name exists.
    The check is an over-approximation: it disallows certain cases in which the old
    program would not have compiled due to ambiguity, for example.
    
    Two subtle additional difficulties:
    
    - Constructors are visible in a datatype and in its parent module.  This means
    that without special care we would disallow expressions like `Option.Some`.
    
    - Code that was previously ambiguous now compiles unambiguously.  One specific
    example is datatype constructors: previously, if two datatypes in a module
    defined same-named constructors, references to `Module.Constructor` were
    ambiguous.  Now, if one of the datatype has the same name as the module, then
    such references are legal and unambiguously resolve to the constructors of that
    datatype.
    cpitclaudel committed Sep 16, 2022
    Configuration menu
    Copy the full SHA
    33ee242 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f3427f6 View commit details
    Browse the repository at this point in the history

Commits on Sep 19, 2022

  1. Configuration menu
    Copy the full SHA
    a8eccfb View commit details
    Browse the repository at this point in the history

Commits on Sep 20, 2022

  1. Fix typo in comment

    RustanLeino committed Sep 20, 2022
    Configuration menu
    Copy the full SHA
    dfaf7fd View commit details
    Browse the repository at this point in the history

Commits on Sep 21, 2022

  1. Merge branch 'master' into issue-1996

    # Conflicts:
    #	RELEASE_NOTES.md
    RustanLeino committed Sep 21, 2022
    Configuration menu
    Copy the full SHA
    55f19a9 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    cfdffb4 View commit details
    Browse the repository at this point in the history