Skip to content

Commit 51a60a6

Browse files
authored
Merge pull request swiftlang#32274 from CodaFi/transport-tycoon
Enable "Direct Intramodule Dependencies" By Default
2 parents c7efed9 + 3228a59 commit 51a60a6

File tree

176 files changed

+1164
-593
lines changed

Some content is hidden

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

176 files changed

+1164
-593
lines changed

include/swift/AST/EvaluatorDependencies.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,19 @@ struct DependencyRecorder {
237237
friend DependencyCollector;
238238

239239
enum class Mode {
240-
// Enables the current "status quo" behavior of the dependency collector.
241-
//
242-
// By default, the dependency collector moves to register dependencies in
243-
// the referenced name trackers at the top of the active dependency stack.
244-
StatusQuo,
245-
// Enables an experimental mode to only register private dependencies.
240+
// Enables the status quo of recording direct dependencies.
246241
//
247242
// This mode restricts the dependency collector to ignore changes of
248243
// scope. This has practical effect of charging all unqualified lookups to
249244
// the primary file being acted upon instead of to the destination file.
250-
ExperimentalPrivateDependencies,
245+
DirectDependencies,
246+
// Enables a legacy mode of dependency tracking that makes a distinction
247+
// between private and cascading edges, and does not directly capture
248+
// transitive dependencies.
249+
//
250+
// By default, the dependency collector moves to register dependencies in
251+
// the referenced name trackers at the top of the active dependency stack.
252+
LegacyCascadingDependencies,
251253
};
252254

253255
private:
@@ -305,9 +307,9 @@ struct DependencyRecorder {
305307
if (dependencySources.empty())
306308
return nullptr;
307309
switch (mode) {
308-
case Mode::StatusQuo:
310+
case Mode::LegacyCascadingDependencies:
309311
return dependencySources.back().getPointer();
310-
case Mode::ExperimentalPrivateDependencies:
312+
case Mode::DirectDependencies:
311313
return dependencySources.front().getPointer();
312314
}
313315
}
@@ -347,9 +349,9 @@ struct DependencyRecorder {
347349
/// If there is no active scope, the result always cascades.
348350
bool isActiveSourceCascading() const {
349351
switch (mode) {
350-
case Mode::StatusQuo:
352+
case Mode::LegacyCascadingDependencies:
351353
return getActiveSourceScope() == evaluator::DependencyScope::Cascading;
352-
case Mode::ExperimentalPrivateDependencies:
354+
case Mode::DirectDependencies:
353355
return false;
354356
}
355357
llvm_unreachable("invalid mode");

include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ namespace swift {
367367

368368
/// Whether to enable a more aggressive mode of incremental dependency
369369
/// gathering that never captures cascading edges.
370-
bool EnableExperientalPrivateIntransitiveDependencies = false;
370+
bool DirectIntramoduleDependencies = true;
371371

372372
/// Enable verification when every SubstitutionMap is constructed.
373373
bool VerifyAllSubstitutionMaps = false;

include/swift/Option/Options.td

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,16 @@ def enable_experimental_concise_pound_file : Flag<["-"],
534534
Flags<[FrontendOption]>,
535535
HelpText<"Enable experimental concise '#file' identifier">;
536536

537-
def experimental_private_intransitive_dependencies : Flag<["-"],
538-
"experimental-private-intransitive-dependencies">,
537+
def enable_direct_intramodule_dependencies : Flag<["-"],
538+
"enable-direct-intramodule-dependencies">,
539539
Flags<[FrontendOption, HelpHidden]>,
540540
HelpText<"Enable experimental dependency tracking that never cascades">;
541541

542+
def disable_direct_intramodule_dependencies : Flag<["-"],
543+
"disable-direct-intramodule-dependencies">,
544+
Flags<[FrontendOption, HelpHidden]>,
545+
HelpText<"Disable experimental dependency tracking that never cascades">;
546+
542547

543548
// Diagnostic control options
544549
def suppress_warnings : Flag<["-"], "suppress-warnings">,

lib/AST/Evaluator.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ void Evaluator::registerRequestFunctions(
6565
static evaluator::DependencyRecorder::Mode
6666
computeDependencyModeFromFlags(const LangOptions &opts) {
6767
using Mode = evaluator::DependencyRecorder::Mode;
68-
if (opts.EnableExperientalPrivateIntransitiveDependencies) {
69-
return Mode::ExperimentalPrivateDependencies;
68+
if (opts.DirectIntramoduleDependencies) {
69+
return Mode::DirectDependencies;
7070
}
7171

72-
return Mode::StatusQuo;
72+
return Mode::LegacyCascadingDependencies;
7373
}
7474

7575
Evaluator::Evaluator(DiagnosticEngine &diags, const LangOptions &opts)
@@ -391,8 +391,7 @@ void evaluator::DependencyRecorder::realize(
391391

392392
void evaluator::DependencyCollector::addUsedMember(NominalTypeDecl *subject,
393393
DeclBaseName name) {
394-
if (parent.mode ==
395-
DependencyRecorder::Mode::ExperimentalPrivateDependencies) {
394+
if (parent.mode == DependencyRecorder::Mode::DirectDependencies) {
396395
scratch.insert(
397396
Reference::usedMember(subject, name, parent.isActiveSourceCascading()));
398397
}
@@ -402,8 +401,7 @@ void evaluator::DependencyCollector::addUsedMember(NominalTypeDecl *subject,
402401

403402
void evaluator::DependencyCollector::addPotentialMember(
404403
NominalTypeDecl *subject) {
405-
if (parent.mode ==
406-
DependencyRecorder::Mode::ExperimentalPrivateDependencies) {
404+
if (parent.mode == DependencyRecorder::Mode::DirectDependencies) {
407405
scratch.insert(
408406
Reference::potentialMember(subject, parent.isActiveSourceCascading()));
409407
}
@@ -412,17 +410,15 @@ void evaluator::DependencyCollector::addPotentialMember(
412410
}
413411

414412
void evaluator::DependencyCollector::addTopLevelName(DeclBaseName name) {
415-
if (parent.mode ==
416-
DependencyRecorder::Mode::ExperimentalPrivateDependencies) {
413+
if (parent.mode == DependencyRecorder::Mode::DirectDependencies) {
417414
scratch.insert(Reference::topLevel(name, parent.isActiveSourceCascading()));
418415
}
419416
return parent.realize(
420417
Reference::topLevel(name, parent.isActiveSourceCascading()));
421418
}
422419

423420
void evaluator::DependencyCollector::addDynamicLookupName(DeclBaseName name) {
424-
if (parent.mode ==
425-
DependencyRecorder::Mode::ExperimentalPrivateDependencies) {
421+
if (parent.mode == DependencyRecorder::Mode::DirectDependencies) {
426422
scratch.insert(Reference::dynamic(name, parent.isActiveSourceCascading()));
427423
}
428424
return parent.realize(
@@ -455,7 +451,11 @@ void evaluator::DependencyRecorder::replay(
455451
assert(!isRecording && "Probably not a good idea to allow nested recording");
456452

457453
auto *source = getActiveDependencySourceOrNull();
458-
if (mode == Mode::StatusQuo || !source || !source->isPrimary()) {
454+
if (mode == Mode::LegacyCascadingDependencies) {
455+
return;
456+
}
457+
458+
if (!source || !source->isPrimary()) {
459459
return;
460460
}
461461

@@ -503,7 +503,7 @@ void evaluator::DependencyRecorder::replay(
503503
void evaluator::DependencyRecorder::unionNearestCachedRequest(
504504
ArrayRef<swift::ActiveRequest> stack,
505505
const DependencyCollector::ReferenceSet &scratch) {
506-
assert(mode != Mode::StatusQuo);
506+
assert(mode != Mode::LegacyCascadingDependencies);
507507
auto nearest = std::find_if(stack.rbegin(), stack.rend(),
508508
[](const auto &req){ return req.isCached(); });
509509
if (nearest == stack.rend()) {

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
254254
inputArgs.AddLastArg(arguments,
255255
options::OPT_verify_incremental_dependencies);
256256
inputArgs.AddLastArg(arguments,
257-
options::OPT_experimental_private_intransitive_dependencies);
257+
options::OPT_enable_direct_intramodule_dependencies,
258+
options::OPT_disable_direct_intramodule_dependencies);
258259

259260
// Pass on any build config options
260261
inputArgs.AddAllArgs(arguments, options::OPT_D);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
435435
if (Args.hasArg(OPT_enable_experimental_additive_arithmetic_derivation))
436436
Opts.EnableExperimentalAdditiveArithmeticDerivedConformances = true;
437437

438-
if (Args.hasArg(OPT_experimental_private_intransitive_dependencies))
439-
Opts.EnableExperientalPrivateIntransitiveDependencies = true;
438+
Opts.DirectIntramoduleDependencies =
439+
Args.hasFlag(OPT_enable_direct_intramodule_dependencies,
440+
OPT_disable_direct_intramodule_dependencies,
441+
Opts.DirectIntramoduleDependencies);
440442

441443
Opts.EnableExperimentalForwardModeDifferentiation |=
442444
Args.hasArg(OPT_enable_experimental_forward_mode_differentiation);

test/Driver/Dependencies/bindings-build-record.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: cp -r %S/Inputs/bindings-build-record/* %t
44
// RUN: %{python} %S/Inputs/touch.py 443865900 %t/*
55

6-
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -driver-show-incremental -output-file-map %t/output.json 2>&1 |%FileCheck %s -check-prefix=MUST-EXEC
6+
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -disable-direct-intramodule-dependencies -driver-show-incremental -output-file-map %t/output.json 2>&1 |%FileCheck %s -check-prefix=MUST-EXEC
77

88
// MUST-EXEC-NOT: warning
99
// MUST-EXEC: inputs: ["./main.swift"], output: {object: "./main.o", swift-dependencies: "./main.swiftdeps"}
@@ -12,34 +12,34 @@
1212
// MUST-EXEC: Disabling incremental build: could not read build record
1313

1414
// RUN: echo '{version: "'$(%swiftc_driver_plain -version | head -n1)'", inputs: {"./main.swift": [443865900, 0], "./other.swift": [443865900, 0], "./yet-another.swift": [443865900, 0]}, build_time: [443865901, 0]}' > %t/main~buildrecord.swiftdeps
15-
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=NO-EXEC
15+
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -disable-direct-intramodule-dependencies -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=NO-EXEC
1616

1717
// NO-EXEC: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: check-dependencies
1818
// NO-EXEC: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: check-dependencies
1919
// NO-EXEC: inputs: ["./yet-another.swift"], output: {{[{].*[}]}}, condition: check-dependencies
2020

2121

2222
// RUN: echo '{version: "'$(%swiftc_driver_plain -version | head -n1)'", inputs: {"./main.swift": [443865900, 0], "./other.swift": !private [443865900, 0], "./yet-another.swift": !dirty [443865900, 0]}, build_time: [443865901, 0]}' > %t/main~buildrecord.swiftdeps
23-
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=BUILD-RECORD
23+
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -disable-direct-intramodule-dependencies -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=BUILD-RECORD
2424

2525
// BUILD-RECORD: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: check-dependencies{{$}}
2626
// BUILD-RECORD: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: run-without-cascading{{$}}
2727
// BUILD-RECORD: inputs: ["./yet-another.swift"], output: {{[{].*[}]$}}
2828

29-
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift ./added.swift -incremental -output-file-map %t/output.json 2>&1 > %t/added.txt
29+
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift ./added.swift -incremental -disable-direct-intramodule-dependencies -output-file-map %t/output.json 2>&1 > %t/added.txt
3030
// RUN: %FileCheck %s -check-prefix=BUILD-RECORD < %t/added.txt
3131
// RUN: %FileCheck %s -check-prefix=FILE-ADDED < %t/added.txt
3232

3333
// FILE-ADDED: inputs: ["./added.swift"], output: {{[{].*[}]}}, condition: newly-added{{$}}
3434

3535
// RUN: %{python} %S/Inputs/touch.py 443865960 %t/main.swift
36-
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=BUILD-RECORD-PLUS-CHANGE
36+
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -disable-direct-intramodule-dependencies -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=BUILD-RECORD-PLUS-CHANGE
3737
// BUILD-RECORD-PLUS-CHANGE: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: run-without-cascading
3838
// BUILD-RECORD-PLUS-CHANGE: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: run-without-cascading{{$}}
3939
// BUILD-RECORD-PLUS-CHANGE: inputs: ["./yet-another.swift"], output: {{[{].*[}]$}}
4040

4141
// RUN: %{python} %S/Inputs/touch.py 443865900 %t/*
42-
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift -incremental -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=FILE-REMOVED
42+
// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift -incremental -disable-direct-intramodule-dependencies -output-file-map %t/output.json 2>&1 | %FileCheck %s -check-prefix=FILE-REMOVED
4343
// FILE-REMOVED: inputs: ["./main.swift"], output: {{[{].*[}]$}}
4444
// FILE-REMOVED: inputs: ["./other.swift"], output: {{[{].*[}]$}}
4545
// FILE-REMOVED-NOT: yet-another.swift

test/Driver/Dependencies/chained-additional-kinds-fine.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
// RUN: cp -r %S/Inputs/chained-additional-kinds-fine/* %t
55
// RUN: touch -t 201401240005 %t/*
66

7-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-FIRST %s
7+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -disable-direct-intramodule-dependencies -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-FIRST %s
88

99
// CHECK-FIRST-NOT: warning
1010
// CHECK-FIRST: Handled main.swift
1111
// CHECK-FIRST: Handled other.swift
1212
// CHECK-FIRST: Handled yet-another.swift
1313

14-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-SECOND %s
14+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -disable-direct-intramodule-dependencies -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-SECOND %s
1515

1616
// CHECK-SECOND-NOT: Handled
1717

1818
// RUN: touch -t 201401240006 %t/other.swift
19-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
19+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -disable-direct-intramodule-dependencies -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
2020

2121
// CHECK-THIRD-DAG: Handled other.swift
2222
// CHECK-THIRD-DAG: Handled main.swift
2323
// CHECK-THIRD-DAG: Handled yet-another.swift
2424

2525
// RUN: touch -t 201401240007 %t/other.swift
26-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./other.swift ./main.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
26+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -disable-direct-intramodule-dependencies -driver-always-rebuild-dependents ./other.swift ./main.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s

test/Driver/Dependencies/chained-after-fine.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
// RUN: touch -t 201401240005 %t/*.swift
77

88
// Generate the build record...
9-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v
9+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -disable-direct-intramodule-dependencies -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v
1010

1111
// ...then reset the .swiftdeps files.
1212
// RUN: cp -r %S/Inputs/chained-after-fine/*.swiftdeps %t
13-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-FIRST %s
13+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -disable-direct-intramodule-dependencies -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-FIRST %s
1414

1515
// CHECK-FIRST-NOT: warning
1616
// CHECK-FIRST-NOT: Handled
1717

1818
// RUN: touch -t 201401240006 %t/other.swift
19-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./yet-another.swift ./main.swift ./other.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
19+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -disable-direct-intramodule-dependencies -driver-always-rebuild-dependents ./yet-another.swift ./main.swift ./other.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
2020

2121
// CHECK-THIRD: Handled main.swift
2222
// CHECK-THIRD: Handled other.swift

0 commit comments

Comments
 (0)