Skip to content

Commit

Permalink
Merge pull request #1891 from swiftwasm/main
Browse files Browse the repository at this point in the history
[pull] swiftwasm from main
  • Loading branch information
pull[bot] committed Oct 2, 2020
2 parents ecd0d8e + 92cb680 commit a1f2fef
Show file tree
Hide file tree
Showing 90 changed files with 2,231 additions and 2,765 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -43,7 +43,6 @@ more links in the SwiftWasm ecosystem.
|---|:---:|:---:|
|**[Ubuntu 18.04](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_18_04_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-18.04-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-18.04-tensorflow)|
|**[macOS 10.13](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_macos_high_sierra_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow)|
|**[Ubuntu 18.04 (GPU)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_18_04_tensorflow_gpu.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-18.04-tensorflow-gpu/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-18.04-tensorflow-gpu)|

## Welcome to Swift

Expand Down
31 changes: 21 additions & 10 deletions include/swift/AST/ASTScope.h
Expand Up @@ -29,7 +29,7 @@
#define SWIFT_AST_AST_SCOPE_H

#include "swift/AST/ASTNode.h"
#include "swift/AST/NameLookup.h" // for DeclVisibilityKind
#include "swift/AST/NameLookup.h"
#include "swift/AST/SimpleRequest.h"
#include "swift/Basic/Compiler.h"
#include "swift/Basic/Debug.h"
Expand Down Expand Up @@ -444,7 +444,6 @@ class ASTScopeImpl {
// It is not an instance variable or inherited type.

static bool lookupLocalBindingsInPattern(const Pattern *p,
DeclVisibilityKind vis,
DeclConsumer consumer);

/// When lookup must stop before the outermost scope, return the scope to stop
Expand Down Expand Up @@ -1024,10 +1023,10 @@ class AbstractPatternEntryScope : public ASTScopeImpl {
public:
PatternBindingDecl *const decl;
const unsigned patternEntryIndex;
const DeclVisibilityKind vis;
const bool isLocalBinding;

AbstractPatternEntryScope(PatternBindingDecl *, unsigned entryIndex,
DeclVisibilityKind);
bool);
virtual ~AbstractPatternEntryScope() {}

const PatternBindingEntry &getPatternEntry() const;
Expand All @@ -1044,8 +1043,8 @@ class AbstractPatternEntryScope : public ASTScopeImpl {
class PatternEntryDeclScope final : public AbstractPatternEntryScope {
public:
PatternEntryDeclScope(PatternBindingDecl *pbDecl, unsigned entryIndex,
DeclVisibilityKind vis)
: AbstractPatternEntryScope(pbDecl, entryIndex, vis) {}
bool isLocalBinding)
: AbstractPatternEntryScope(pbDecl, entryIndex, isLocalBinding) {}
virtual ~PatternEntryDeclScope() {}

protected:
Expand All @@ -1072,8 +1071,8 @@ class PatternEntryInitializerScope final : public AbstractPatternEntryScope {

public:
PatternEntryInitializerScope(PatternBindingDecl *pbDecl, unsigned entryIndex,
DeclVisibilityKind vis)
: AbstractPatternEntryScope(pbDecl, entryIndex, vis),
bool isLocalBinding)
: AbstractPatternEntryScope(pbDecl, entryIndex, isLocalBinding),
initAsWrittenWhenCreated(pbDecl->getOriginalInit(entryIndex)) {}
virtual ~PatternEntryInitializerScope() {}

Expand Down Expand Up @@ -1658,10 +1657,22 @@ class CaseStmtBodyScope final : public ASTScopeImpl {
};

class BraceStmtScope final : public AbstractStmtScope {
BraceStmt *const stmt;

/// Declarations which are in scope from the beginning of the statement.
SmallVector<ValueDecl *, 2> localFuncsAndTypes;

/// Declarations that are normally in scope only after their
/// definition.
SmallVector<VarDecl *, 2> localVars;

public:
BraceStmt *const stmt;
BraceStmtScope(BraceStmt *e) : stmt(e) {}
BraceStmtScope(BraceStmt *e,
SmallVector<ValueDecl *, 2> localFuncsAndTypes,
SmallVector<VarDecl *, 2> localVars)
: stmt(e),
localFuncsAndTypes(localFuncsAndTypes),
localVars(localVars) {}
virtual ~BraceStmtScope() {}

protected:
Expand Down
7 changes: 1 addition & 6 deletions include/swift/AST/AbstractSourceFileDepGraphFactory.h
Expand Up @@ -24,10 +24,6 @@ namespace fine_grained_dependencies {
/// \c SourceFile or a unit test
class AbstractSourceFileDepGraphFactory {
protected:
/// To match the existing system, set this to false.
/// To include even private entities and get intra-file info, set to true.
const bool includePrivateDeps;

/// If there was an error, cannot get accurate info.
const bool hadCompilationError;

Expand All @@ -48,8 +44,7 @@ class AbstractSourceFileDepGraphFactory {
public:
/// Expose this layer to enable faking up a constructor for testing.
/// See the instance variable comments for explanation.
AbstractSourceFileDepGraphFactory(bool includePrivateDeps,
bool hadCompilationError,
AbstractSourceFileDepGraphFactory(bool hadCompilationError,
StringRef swiftDeps,
StringRef fileFingerprint,
bool emitDotFileAfterConstruction,
Expand Down
3 changes: 0 additions & 3 deletions include/swift/AST/Decl.h
Expand Up @@ -950,9 +950,6 @@ class alignas(1 << DeclAlignInBits) Decl {
/// If this returns true, the decl can be safely casted to ValueDecl.
bool isPotentiallyOverridable() const;

/// Returns true if this Decl cannot be seen by any other source file
bool isPrivateToEnclosingFile() const;

/// If an alternative module name is specified for this decl, e.g. using
/// @_originalDefinedIn attribute, this function returns this module name.
StringRef getAlternateModuleName() const;
Expand Down
12 changes: 10 additions & 2 deletions include/swift/AST/NameLookup.h
Expand Up @@ -603,7 +603,7 @@ class AbstractASTScopeDeclConsumer {
/// of type -vs- instance lookup results.
///
/// \return true if the lookup should be stopped at this point.
virtual bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
virtual bool consume(ArrayRef<ValueDecl *> values,
NullablePtr<DeclContext> baseDC = nullptr) = 0;

/// Look for members of a nominal type or extension scope.
Expand All @@ -613,6 +613,14 @@ class AbstractASTScopeDeclConsumer {
lookInMembers(DeclContext *const scopeDC,
NominalTypeDecl *const nominal) = 0;

/// Called for local VarDecls that might not yet be in scope.
///
/// Note that the set of VarDecls visited here are going to be a
/// superset of those visited in consume().
virtual bool consumePossiblyNotInScope(ArrayRef<VarDecl *> values) {
return false;
}

/// Called right before looking at the parent scope of a BraceStmt.
///
/// \return true if the lookup should be stopped at this point.
Expand All @@ -636,7 +644,7 @@ class ASTScopeDeclGatherer : public AbstractASTScopeDeclConsumer {
public:
virtual ~ASTScopeDeclGatherer() = default;

bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
bool consume(ArrayRef<ValueDecl *> values,
NullablePtr<DeclContext> baseDC = nullptr) override;

/// Eventually this functionality should move into ASTScopeLookup
Expand Down
11 changes: 0 additions & 11 deletions include/swift/Basic/LangOptions.h
Expand Up @@ -330,21 +330,10 @@ namespace swift {
/// of active clauses aren't hoisted into the enclosing scope.
bool DisablePoundIfEvaluation = false;

/// Instead of hashing tokens inside of NominalType and ExtensionBodies into
/// the interface hash, hash them into per-iterable-decl-context
/// fingerprints. Fine-grained dependency types won't dirty every provides
/// in a file when the user adds a member to, e.g., a struct.
bool EnableTypeFingerprints = true;

/// When using fine-grained dependencies, emit dot files for every swiftdeps
/// file.
bool EmitFineGrainedDependencySourcefileDotFiles = false;

/// To mimic existing system, set to false.
/// To experiment with including file-private and private dependency info,
/// set to true.
bool FineGrainedDependenciesIncludeIntrafileOnes = false;

/// Whether to enable experimental differentiable programming features:
/// `@differentiable` declaration attribute, etc.
bool EnableExperimentalDifferentiableProgramming = false;
Expand Down
15 changes: 0 additions & 15 deletions include/swift/Driver/Compilation.h
Expand Up @@ -265,19 +265,13 @@ class Compilation {
const bool OnlyOneDependencyFile;

private:
/// Is the parser recording token hashes for each type body?
const bool EnableTypeFingerprints;

/// Helpful for debugging, but slows down the driver. So, only turn on when
/// needed.
const bool VerifyFineGrainedDependencyGraphAfterEveryImport;
/// Helpful for debugging, but slows down the driver. So, only turn on when
/// needed.
const bool EmitFineGrainedDependencyDotFileAfterEveryImport;

/// Experiment with intrafile dependencies
const bool FineGrainedDependenciesIncludeIntrafileOnes;

/// Experiment with source-range-based dependencies
const bool EnableSourceRangeDependencies;

Expand Down Expand Up @@ -319,11 +313,8 @@ class Compilation {
bool ShowDriverTimeCompilation = false,
std::unique_ptr<UnifiedStatsReporter> Stats = nullptr,
bool OnlyOneDependencyFile = false,
bool EnableTypeFingerprints =
LangOptions().EnableTypeFingerprints,
bool VerifyFineGrainedDependencyGraphAfterEveryImport = false,
bool EmitFineGrainedDependencyDotFileAfterEveryImport = false,
bool FineGrainedDependenciesIncludeIntrafileOnes = false,
bool EnableSourceRangeDependencies = false,
bool CompareIncrementalSchemes = false,
StringRef CompareIncrementalSchemesPath = "",
Expand Down Expand Up @@ -386,8 +377,6 @@ class Compilation {
}
void disableIncrementalBuild(Twine why);

bool getEnableTypeFingerprints() const { return EnableTypeFingerprints; }

bool getVerifyFineGrainedDependencyGraphAfterEveryImport() const {
return VerifyFineGrainedDependencyGraphAfterEveryImport;
}
Expand All @@ -396,10 +385,6 @@ class Compilation {
return EmitFineGrainedDependencyDotFileAfterEveryImport;
}

bool getFineGrainedDependenciesIncludeIntrafileOnes() const {
return FineGrainedDependenciesIncludeIntrafileOnes;
}

bool getEnableSourceRangeDependencies() const {
return EnableSourceRangeDependencies;
}
Expand Down
9 changes: 2 additions & 7 deletions include/swift/Driver/FineGrainedDependencyDriverGraph.h
Expand Up @@ -189,8 +189,6 @@ class ModuleDepGraph {
const bool verifyFineGrainedDependencyGraphAfterEveryImport;
const bool emitFineGrainedDependencyDotFileAfterEveryImport;

const bool EnableTypeFingerprints;

private:
/// If tracing dependencies, holds a vector used to hold the current path
/// def - use/def - use/def - ...
Expand Down Expand Up @@ -296,14 +294,12 @@ class ModuleDepGraph {
/// \p stats may be null
ModuleDepGraph(const bool verifyFineGrainedDependencyGraphAfterEveryImport,
const bool emitFineGrainedDependencyDotFileAfterEveryImport,
const bool EnableTypeFingerprints,
const bool shouldTraceDependencies,
UnifiedStatsReporter *stats)
: verifyFineGrainedDependencyGraphAfterEveryImport(
verifyFineGrainedDependencyGraphAfterEveryImport),
emitFineGrainedDependencyDotFileAfterEveryImport(
emitFineGrainedDependencyDotFileAfterEveryImport),
EnableTypeFingerprints(EnableTypeFingerprints),
currentPathIfTracing(
shouldTraceDependencies
? llvm::Optional<std::vector<const ModuleDepGraphNode *>>(
Expand All @@ -314,11 +310,10 @@ class ModuleDepGraph {
}

/// For unit tests.
ModuleDepGraph(const bool EnableTypeFingerprints,
const bool EmitDotFilesForDebugging = false)
ModuleDepGraph(const bool EmitDotFilesForDebugging = false)
: ModuleDepGraph(
true, /*emitFineGrainedDependencyDotFileAfterEveryImport=*/
EmitDotFilesForDebugging, EnableTypeFingerprints, false, nullptr) {}
EmitDotFilesForDebugging, false, nullptr) {}

//============================================================================
// MARK: ModuleDepGraph - updating from a switdeps file
Expand Down
13 changes: 0 additions & 13 deletions include/swift/Option/Options.td
Expand Up @@ -139,14 +139,6 @@ def driver_always_rebuild_dependents :
Flag<["-"], "driver-always-rebuild-dependents">, InternalDebugOpt,
HelpText<"Always rebuild dependents of files that have been modified">;

def enable_type_fingerprints :
Flag<["-"], "enable-type-fingerprints">, Flags<[FrontendOption, HelpHidden]>,
HelpText<"Enable per-nominal and extension body fingerprints">;

def disable_type_fingerprints :
Flag<["-"], "disable-type-fingerprints">, Flags<[FrontendOption, HelpHidden]>,
HelpText<"Disable per-nominal and extension body fingerprints">;

def enable_only_one_dependency_file :
Flag<["-"], "enable-only-one-dependency-file">, Flags<[DoesNotAffectIncrementalBuild]>,
HelpText<"Enables incremental build optimization that only produces one dependencies file">;
Expand Down Expand Up @@ -190,11 +182,6 @@ Flag<["-"], "driver-emit-fine-grained-dependency-dot-file-after-every-import">,
InternalDebugOpt,
HelpText<"Emit dot files every time driver imports an fine-grained swiftdeps file.">;

def fine_grained_dependency_include_intrafile :
Flag<["-"], "fine-grained-dependency-include-intrafile">,
Flags<[FrontendOption, HelpHidden]>,
HelpText<"Include within-file dependencies.">;

def emit_fine_grained_dependency_sourcefile_dot_files :
Flag<["-"], "emit-fine-grained-dependency-sourcefile-dot-files">,
Flags<[FrontendOption, HelpHidden]>,
Expand Down
51 changes: 36 additions & 15 deletions lib/AST/ASTScopeCreation.cpp
Expand Up @@ -667,10 +667,30 @@ class NodeAdder

NullablePtr<ASTScopeImpl> visitBraceStmt(BraceStmt *bs, ASTScopeImpl *p,
ScopeCreator &scopeCreator) {
SmallVector<ValueDecl *, 2> localFuncsAndTypes;
SmallVector<VarDecl *, 2> localVars;

// All types and functions are visible anywhere within a brace statement
// scope. When ordering matters (i.e. var decl) we will have split the brace
// statement into nested scopes.
for (auto braceElement : bs->getElements()) {
if (auto localBinding = braceElement.dyn_cast<Decl *>()) {
if (auto *vd = dyn_cast<ValueDecl>(localBinding)) {
if (isa<FuncDecl>(vd) || isa<TypeDecl>(vd)) {
localFuncsAndTypes.push_back(vd);
} else if (auto *var = dyn_cast<VarDecl>(localBinding)) {
localVars.push_back(var);
}
}
}
}

auto maybeBraceScope =
scopeCreator.ifUniqueConstructExpandAndInsert<BraceStmtScope>(p, bs);
scopeCreator.ifUniqueConstructExpandAndInsert<BraceStmtScope>(
p, bs, std::move(localFuncsAndTypes), std::move(localVars));
if (auto *s = scopeCreator.getASTContext().Stats)
++s->getFrontendCounters().NumBraceStmtASTScopes;

return maybeBraceScope.getPtrOr(p);
}

Expand All @@ -681,23 +701,23 @@ class NodeAdder
if (auto *var = patternBinding->getSingleVar())
scopeCreator.addChildrenForKnownAttributes(var, parentScope);

const bool isLocalBinding = patternBinding->getDeclContext()->isLocalContext();

const DeclVisibilityKind vis =
isLocalBinding ? DeclVisibilityKind::LocalVariable
: DeclVisibilityKind::MemberOfCurrentNominal;
auto *insertionPoint = parentScope;
for (auto i : range(patternBinding->getNumPatternEntries())) {
bool isLocalBinding = false;
if (auto *varDecl = patternBinding->getAnchoringVarDecl(i)) {
isLocalBinding = varDecl->getDeclContext()->isLocalContext();
}

insertionPoint =
scopeCreator
.ifUniqueConstructExpandAndInsert<PatternEntryDeclScope>(
insertionPoint, patternBinding, i, vis)
insertionPoint, patternBinding, i, isLocalBinding)
.getPtrOr(insertionPoint);
}

ASTScopeAssert(isLocalBinding || insertionPoint == parentScope,
"Bindings at the top-level or members of types should "
"not change the insertion point");
ASTScopeAssert(isLocalBinding || insertionPoint == parentScope,
"Bindings at the top-level or members of types should "
"not change the insertion point");
}

return insertionPoint;
}
Expand Down Expand Up @@ -971,7 +991,7 @@ PatternEntryDeclScope::expandAScopeThatCreatesANewInsertionPoint(
"Original inits are always after the '='");
scopeCreator
.constructExpandAndInsertUncheckable<PatternEntryInitializerScope>(
this, decl, patternEntryIndex, vis);
this, decl, patternEntryIndex, isLocalBinding);
}

// Add accessors for the variables in this pattern.
Expand All @@ -982,7 +1002,7 @@ PatternEntryDeclScope::expandAScopeThatCreatesANewInsertionPoint(
// In local context, the PatternEntryDeclScope becomes the insertion point, so
// that all any bindings introduecd by the pattern are in scope for subsequent
// lookups.
if (vis == DeclVisibilityKind::LocalVariable)
if (isLocalBinding)
return {this, "All code that follows is inside this scope"};

return {getParent().get(), "Global and type members do not introduce scopes"};
Expand Down Expand Up @@ -1358,8 +1378,9 @@ ASTScopeImpl *LabeledConditionalStmtScope::createNestedConditionalClauseScopes(

AbstractPatternEntryScope::AbstractPatternEntryScope(
PatternBindingDecl *declBeingScoped, unsigned entryIndex,
DeclVisibilityKind vis)
: decl(declBeingScoped), patternEntryIndex(entryIndex), vis(vis) {
bool isLocalBinding)
: decl(declBeingScoped), patternEntryIndex(entryIndex),
isLocalBinding(isLocalBinding) {
ASTScopeAssert(entryIndex < declBeingScoped->getPatternList().size(),
"out of bounds");
}
Expand Down

0 comments on commit a1f2fef

Please sign in to comment.