Skip to content

Commit a1f2fef

Browse files
authored
Merge pull request #1891 from swiftwasm/main
[pull] swiftwasm from main
2 parents ecd0d8e + 92cb680 commit a1f2fef

File tree

90 files changed

+2231
-2765
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2231
-2765
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ more links in the SwiftWasm ecosystem.
4343
|---|:---:|:---:|
4444
|**[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)|
4545
|**[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)|
46-
|**[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)|
4746

4847
## Welcome to Swift
4948

include/swift/AST/ASTScope.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define SWIFT_AST_AST_SCOPE_H
3030

3131
#include "swift/AST/ASTNode.h"
32-
#include "swift/AST/NameLookup.h" // for DeclVisibilityKind
32+
#include "swift/AST/NameLookup.h"
3333
#include "swift/AST/SimpleRequest.h"
3434
#include "swift/Basic/Compiler.h"
3535
#include "swift/Basic/Debug.h"
@@ -444,7 +444,6 @@ class ASTScopeImpl {
444444
// It is not an instance variable or inherited type.
445445

446446
static bool lookupLocalBindingsInPattern(const Pattern *p,
447-
DeclVisibilityKind vis,
448447
DeclConsumer consumer);
449448

450449
/// When lookup must stop before the outermost scope, return the scope to stop
@@ -1024,10 +1023,10 @@ class AbstractPatternEntryScope : public ASTScopeImpl {
10241023
public:
10251024
PatternBindingDecl *const decl;
10261025
const unsigned patternEntryIndex;
1027-
const DeclVisibilityKind vis;
1026+
const bool isLocalBinding;
10281027

10291028
AbstractPatternEntryScope(PatternBindingDecl *, unsigned entryIndex,
1030-
DeclVisibilityKind);
1029+
bool);
10311030
virtual ~AbstractPatternEntryScope() {}
10321031

10331032
const PatternBindingEntry &getPatternEntry() const;
@@ -1044,8 +1043,8 @@ class AbstractPatternEntryScope : public ASTScopeImpl {
10441043
class PatternEntryDeclScope final : public AbstractPatternEntryScope {
10451044
public:
10461045
PatternEntryDeclScope(PatternBindingDecl *pbDecl, unsigned entryIndex,
1047-
DeclVisibilityKind vis)
1048-
: AbstractPatternEntryScope(pbDecl, entryIndex, vis) {}
1046+
bool isLocalBinding)
1047+
: AbstractPatternEntryScope(pbDecl, entryIndex, isLocalBinding) {}
10491048
virtual ~PatternEntryDeclScope() {}
10501049

10511050
protected:
@@ -1072,8 +1071,8 @@ class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
10721071

10731072
public:
10741073
PatternEntryInitializerScope(PatternBindingDecl *pbDecl, unsigned entryIndex,
1075-
DeclVisibilityKind vis)
1076-
: AbstractPatternEntryScope(pbDecl, entryIndex, vis),
1074+
bool isLocalBinding)
1075+
: AbstractPatternEntryScope(pbDecl, entryIndex, isLocalBinding),
10771076
initAsWrittenWhenCreated(pbDecl->getOriginalInit(entryIndex)) {}
10781077
virtual ~PatternEntryInitializerScope() {}
10791078

@@ -1658,10 +1657,22 @@ class CaseStmtBodyScope final : public ASTScopeImpl {
16581657
};
16591658

16601659
class BraceStmtScope final : public AbstractStmtScope {
1660+
BraceStmt *const stmt;
1661+
1662+
/// Declarations which are in scope from the beginning of the statement.
1663+
SmallVector<ValueDecl *, 2> localFuncsAndTypes;
1664+
1665+
/// Declarations that are normally in scope only after their
1666+
/// definition.
1667+
SmallVector<VarDecl *, 2> localVars;
16611668

16621669
public:
1663-
BraceStmt *const stmt;
1664-
BraceStmtScope(BraceStmt *e) : stmt(e) {}
1670+
BraceStmtScope(BraceStmt *e,
1671+
SmallVector<ValueDecl *, 2> localFuncsAndTypes,
1672+
SmallVector<VarDecl *, 2> localVars)
1673+
: stmt(e),
1674+
localFuncsAndTypes(localFuncsAndTypes),
1675+
localVars(localVars) {}
16651676
virtual ~BraceStmtScope() {}
16661677

16671678
protected:

include/swift/AST/AbstractSourceFileDepGraphFactory.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ namespace fine_grained_dependencies {
2424
/// \c SourceFile or a unit test
2525
class AbstractSourceFileDepGraphFactory {
2626
protected:
27-
/// To match the existing system, set this to false.
28-
/// To include even private entities and get intra-file info, set to true.
29-
const bool includePrivateDeps;
30-
3127
/// If there was an error, cannot get accurate info.
3228
const bool hadCompilationError;
3329

@@ -48,8 +44,7 @@ class AbstractSourceFileDepGraphFactory {
4844
public:
4945
/// Expose this layer to enable faking up a constructor for testing.
5046
/// See the instance variable comments for explanation.
51-
AbstractSourceFileDepGraphFactory(bool includePrivateDeps,
52-
bool hadCompilationError,
47+
AbstractSourceFileDepGraphFactory(bool hadCompilationError,
5348
StringRef swiftDeps,
5449
StringRef fileFingerprint,
5550
bool emitDotFileAfterConstruction,

include/swift/AST/Decl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,9 +950,6 @@ class alignas(1 << DeclAlignInBits) Decl {
950950
/// If this returns true, the decl can be safely casted to ValueDecl.
951951
bool isPotentiallyOverridable() const;
952952

953-
/// Returns true if this Decl cannot be seen by any other source file
954-
bool isPrivateToEnclosingFile() const;
955-
956953
/// If an alternative module name is specified for this decl, e.g. using
957954
/// @_originalDefinedIn attribute, this function returns this module name.
958955
StringRef getAlternateModuleName() const;

include/swift/AST/NameLookup.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ class AbstractASTScopeDeclConsumer {
603603
/// of type -vs- instance lookup results.
604604
///
605605
/// \return true if the lookup should be stopped at this point.
606-
virtual bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
606+
virtual bool consume(ArrayRef<ValueDecl *> values,
607607
NullablePtr<DeclContext> baseDC = nullptr) = 0;
608608

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

616+
/// Called for local VarDecls that might not yet be in scope.
617+
///
618+
/// Note that the set of VarDecls visited here are going to be a
619+
/// superset of those visited in consume().
620+
virtual bool consumePossiblyNotInScope(ArrayRef<VarDecl *> values) {
621+
return false;
622+
}
623+
616624
/// Called right before looking at the parent scope of a BraceStmt.
617625
///
618626
/// \return true if the lookup should be stopped at this point.
@@ -636,7 +644,7 @@ class ASTScopeDeclGatherer : public AbstractASTScopeDeclConsumer {
636644
public:
637645
virtual ~ASTScopeDeclGatherer() = default;
638646

639-
bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
647+
bool consume(ArrayRef<ValueDecl *> values,
640648
NullablePtr<DeclContext> baseDC = nullptr) override;
641649

642650
/// Eventually this functionality should move into ASTScopeLookup

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,21 +330,10 @@ namespace swift {
330330
/// of active clauses aren't hoisted into the enclosing scope.
331331
bool DisablePoundIfEvaluation = false;
332332

333-
/// Instead of hashing tokens inside of NominalType and ExtensionBodies into
334-
/// the interface hash, hash them into per-iterable-decl-context
335-
/// fingerprints. Fine-grained dependency types won't dirty every provides
336-
/// in a file when the user adds a member to, e.g., a struct.
337-
bool EnableTypeFingerprints = true;
338-
339333
/// When using fine-grained dependencies, emit dot files for every swiftdeps
340334
/// file.
341335
bool EmitFineGrainedDependencySourcefileDotFiles = false;
342336

343-
/// To mimic existing system, set to false.
344-
/// To experiment with including file-private and private dependency info,
345-
/// set to true.
346-
bool FineGrainedDependenciesIncludeIntrafileOnes = false;
347-
348337
/// Whether to enable experimental differentiable programming features:
349338
/// `@differentiable` declaration attribute, etc.
350339
bool EnableExperimentalDifferentiableProgramming = false;

include/swift/Driver/Compilation.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,13 @@ class Compilation {
265265
const bool OnlyOneDependencyFile;
266266

267267
private:
268-
/// Is the parser recording token hashes for each type body?
269-
const bool EnableTypeFingerprints;
270-
271268
/// Helpful for debugging, but slows down the driver. So, only turn on when
272269
/// needed.
273270
const bool VerifyFineGrainedDependencyGraphAfterEveryImport;
274271
/// Helpful for debugging, but slows down the driver. So, only turn on when
275272
/// needed.
276273
const bool EmitFineGrainedDependencyDotFileAfterEveryImport;
277274

278-
/// Experiment with intrafile dependencies
279-
const bool FineGrainedDependenciesIncludeIntrafileOnes;
280-
281275
/// Experiment with source-range-based dependencies
282276
const bool EnableSourceRangeDependencies;
283277

@@ -319,11 +313,8 @@ class Compilation {
319313
bool ShowDriverTimeCompilation = false,
320314
std::unique_ptr<UnifiedStatsReporter> Stats = nullptr,
321315
bool OnlyOneDependencyFile = false,
322-
bool EnableTypeFingerprints =
323-
LangOptions().EnableTypeFingerprints,
324316
bool VerifyFineGrainedDependencyGraphAfterEveryImport = false,
325317
bool EmitFineGrainedDependencyDotFileAfterEveryImport = false,
326-
bool FineGrainedDependenciesIncludeIntrafileOnes = false,
327318
bool EnableSourceRangeDependencies = false,
328319
bool CompareIncrementalSchemes = false,
329320
StringRef CompareIncrementalSchemesPath = "",
@@ -386,8 +377,6 @@ class Compilation {
386377
}
387378
void disableIncrementalBuild(Twine why);
388379

389-
bool getEnableTypeFingerprints() const { return EnableTypeFingerprints; }
390-
391380
bool getVerifyFineGrainedDependencyGraphAfterEveryImport() const {
392381
return VerifyFineGrainedDependencyGraphAfterEveryImport;
393382
}
@@ -396,10 +385,6 @@ class Compilation {
396385
return EmitFineGrainedDependencyDotFileAfterEveryImport;
397386
}
398387

399-
bool getFineGrainedDependenciesIncludeIntrafileOnes() const {
400-
return FineGrainedDependenciesIncludeIntrafileOnes;
401-
}
402-
403388
bool getEnableSourceRangeDependencies() const {
404389
return EnableSourceRangeDependencies;
405390
}

include/swift/Driver/FineGrainedDependencyDriverGraph.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ class ModuleDepGraph {
189189
const bool verifyFineGrainedDependencyGraphAfterEveryImport;
190190
const bool emitFineGrainedDependencyDotFileAfterEveryImport;
191191

192-
const bool EnableTypeFingerprints;
193-
194192
private:
195193
/// If tracing dependencies, holds a vector used to hold the current path
196194
/// def - use/def - use/def - ...
@@ -296,14 +294,12 @@ class ModuleDepGraph {
296294
/// \p stats may be null
297295
ModuleDepGraph(const bool verifyFineGrainedDependencyGraphAfterEveryImport,
298296
const bool emitFineGrainedDependencyDotFileAfterEveryImport,
299-
const bool EnableTypeFingerprints,
300297
const bool shouldTraceDependencies,
301298
UnifiedStatsReporter *stats)
302299
: verifyFineGrainedDependencyGraphAfterEveryImport(
303300
verifyFineGrainedDependencyGraphAfterEveryImport),
304301
emitFineGrainedDependencyDotFileAfterEveryImport(
305302
emitFineGrainedDependencyDotFileAfterEveryImport),
306-
EnableTypeFingerprints(EnableTypeFingerprints),
307303
currentPathIfTracing(
308304
shouldTraceDependencies
309305
? llvm::Optional<std::vector<const ModuleDepGraphNode *>>(
@@ -314,11 +310,10 @@ class ModuleDepGraph {
314310
}
315311

316312
/// For unit tests.
317-
ModuleDepGraph(const bool EnableTypeFingerprints,
318-
const bool EmitDotFilesForDebugging = false)
313+
ModuleDepGraph(const bool EmitDotFilesForDebugging = false)
319314
: ModuleDepGraph(
320315
true, /*emitFineGrainedDependencyDotFileAfterEveryImport=*/
321-
EmitDotFilesForDebugging, EnableTypeFingerprints, false, nullptr) {}
316+
EmitDotFilesForDebugging, false, nullptr) {}
322317

323318
//============================================================================
324319
// MARK: ModuleDepGraph - updating from a switdeps file

include/swift/Option/Options.td

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,6 @@ def driver_always_rebuild_dependents :
139139
Flag<["-"], "driver-always-rebuild-dependents">, InternalDebugOpt,
140140
HelpText<"Always rebuild dependents of files that have been modified">;
141141

142-
def enable_type_fingerprints :
143-
Flag<["-"], "enable-type-fingerprints">, Flags<[FrontendOption, HelpHidden]>,
144-
HelpText<"Enable per-nominal and extension body fingerprints">;
145-
146-
def disable_type_fingerprints :
147-
Flag<["-"], "disable-type-fingerprints">, Flags<[FrontendOption, HelpHidden]>,
148-
HelpText<"Disable per-nominal and extension body fingerprints">;
149-
150142
def enable_only_one_dependency_file :
151143
Flag<["-"], "enable-only-one-dependency-file">, Flags<[DoesNotAffectIncrementalBuild]>,
152144
HelpText<"Enables incremental build optimization that only produces one dependencies file">;
@@ -190,11 +182,6 @@ Flag<["-"], "driver-emit-fine-grained-dependency-dot-file-after-every-import">,
190182
InternalDebugOpt,
191183
HelpText<"Emit dot files every time driver imports an fine-grained swiftdeps file.">;
192184

193-
def fine_grained_dependency_include_intrafile :
194-
Flag<["-"], "fine-grained-dependency-include-intrafile">,
195-
Flags<[FrontendOption, HelpHidden]>,
196-
HelpText<"Include within-file dependencies.">;
197-
198185
def emit_fine_grained_dependency_sourcefile_dot_files :
199186
Flag<["-"], "emit-fine-grained-dependency-sourcefile-dot-files">,
200187
Flags<[FrontendOption, HelpHidden]>,

lib/AST/ASTScopeCreation.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,30 @@ class NodeAdder
667667

668668
NullablePtr<ASTScopeImpl> visitBraceStmt(BraceStmt *bs, ASTScopeImpl *p,
669669
ScopeCreator &scopeCreator) {
670+
SmallVector<ValueDecl *, 2> localFuncsAndTypes;
671+
SmallVector<VarDecl *, 2> localVars;
672+
673+
// All types and functions are visible anywhere within a brace statement
674+
// scope. When ordering matters (i.e. var decl) we will have split the brace
675+
// statement into nested scopes.
676+
for (auto braceElement : bs->getElements()) {
677+
if (auto localBinding = braceElement.dyn_cast<Decl *>()) {
678+
if (auto *vd = dyn_cast<ValueDecl>(localBinding)) {
679+
if (isa<FuncDecl>(vd) || isa<TypeDecl>(vd)) {
680+
localFuncsAndTypes.push_back(vd);
681+
} else if (auto *var = dyn_cast<VarDecl>(localBinding)) {
682+
localVars.push_back(var);
683+
}
684+
}
685+
}
686+
}
687+
670688
auto maybeBraceScope =
671-
scopeCreator.ifUniqueConstructExpandAndInsert<BraceStmtScope>(p, bs);
689+
scopeCreator.ifUniqueConstructExpandAndInsert<BraceStmtScope>(
690+
p, bs, std::move(localFuncsAndTypes), std::move(localVars));
672691
if (auto *s = scopeCreator.getASTContext().Stats)
673692
++s->getFrontendCounters().NumBraceStmtASTScopes;
693+
674694
return maybeBraceScope.getPtrOr(p);
675695
}
676696

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

684-
const bool isLocalBinding = patternBinding->getDeclContext()->isLocalContext();
685-
686-
const DeclVisibilityKind vis =
687-
isLocalBinding ? DeclVisibilityKind::LocalVariable
688-
: DeclVisibilityKind::MemberOfCurrentNominal;
689704
auto *insertionPoint = parentScope;
690705
for (auto i : range(patternBinding->getNumPatternEntries())) {
706+
bool isLocalBinding = false;
707+
if (auto *varDecl = patternBinding->getAnchoringVarDecl(i)) {
708+
isLocalBinding = varDecl->getDeclContext()->isLocalContext();
709+
}
710+
691711
insertionPoint =
692712
scopeCreator
693713
.ifUniqueConstructExpandAndInsert<PatternEntryDeclScope>(
694-
insertionPoint, patternBinding, i, vis)
714+
insertionPoint, patternBinding, i, isLocalBinding)
695715
.getPtrOr(insertionPoint);
696-
}
697716

698-
ASTScopeAssert(isLocalBinding || insertionPoint == parentScope,
699-
"Bindings at the top-level or members of types should "
700-
"not change the insertion point");
717+
ASTScopeAssert(isLocalBinding || insertionPoint == parentScope,
718+
"Bindings at the top-level or members of types should "
719+
"not change the insertion point");
720+
}
701721

702722
return insertionPoint;
703723
}
@@ -971,7 +991,7 @@ PatternEntryDeclScope::expandAScopeThatCreatesANewInsertionPoint(
971991
"Original inits are always after the '='");
972992
scopeCreator
973993
.constructExpandAndInsertUncheckable<PatternEntryInitializerScope>(
974-
this, decl, patternEntryIndex, vis);
994+
this, decl, patternEntryIndex, isLocalBinding);
975995
}
976996

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

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

13591379
AbstractPatternEntryScope::AbstractPatternEntryScope(
13601380
PatternBindingDecl *declBeingScoped, unsigned entryIndex,
1361-
DeclVisibilityKind vis)
1362-
: decl(declBeingScoped), patternEntryIndex(entryIndex), vis(vis) {
1381+
bool isLocalBinding)
1382+
: decl(declBeingScoped), patternEntryIndex(entryIndex),
1383+
isLocalBinding(isLocalBinding) {
13631384
ASTScopeAssert(entryIndex < declBeingScoped->getPatternList().size(),
13641385
"out of bounds");
13651386
}

0 commit comments

Comments
 (0)