forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Caching] Preliminary simple macro support for caching
Preliminary caching support for macro. Current implementation only supports macros that built into the toolchain by: * Inserting the plugin into the CASFS * Lookup plugin via physical file system
- Loading branch information
1 parent
bca1dd7
commit 121fc4e
Showing
4 changed files
with
243 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// REQUIRES: swift_swift_parser | ||
|
||
// RUN: %empty-directory(%t) | ||
|
||
// RUN: %target-swift-frontend -scan-dependencies -module-name MyApp -module-cache-path %t/clang-module-cache -O \ | ||
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \ | ||
// RUN: %s -o %t/deps.json -swift-version 5 -cache-compile-job -cas-path %t/cas -plugin-path %swift-plugin-dir | ||
|
||
// RUN: %S/Inputs/SwiftDepsExtractor.py %t/deps.json MyApp casFSRootID > %t/fs.casid | ||
// RUN: llvm-cas -cas %t/cas -ls-tree-recursive @%t/fs.casid | %FileCheck %s --check-prefix=FS | ||
|
||
// FS: SwiftMacros | ||
|
||
// RUN: %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/SwiftShims.cmd | ||
// RUN: %swift_frontend_plain @%t/SwiftShims.cmd | ||
|
||
// RUN: %S/Inputs/BuildCommandExtractor.py %t/deps.json Swift > %t/Swift.cmd | ||
// RUN: %swift_frontend_plain @%t/Swift.cmd | ||
|
||
// RUN: %S/Inputs/SwiftDepsExtractor.py %t/deps.json Swift moduleCacheKey | tr -d '\n' > %t/Swift.key | ||
// RUN: %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:SwiftShims moduleCacheKey | tr -d '\n' > %t/Shims.key | ||
// RUN: %S/Inputs/BuildCommandExtractor.py %t/deps.json MyApp > %t/MyApp.cmd | ||
|
||
// RUN: echo "[{" > %/t/map.json | ||
// RUN: echo "\"moduleName\": \"Swift\"," >> %/t/map.json | ||
// RUN: echo "\"modulePath\": \"Swift.swiftmodule\"," >> %/t/map.json | ||
// RUN: echo -n "\"moduleCacheKey\": " >> %/t/map.json | ||
// RUN: cat %t/Swift.key >> %/t/map.json | ||
// RUN: echo "," >> %/t/map.json | ||
// RUN: echo "\"isFramework\": false" >> %/t/map.json | ||
// RUN: echo "}," >> %/t/map.json | ||
// RUN: echo "{" >> %/t/map.json | ||
// RUN: echo "\"moduleName\": \"SwiftShims\"," >> %/t/map.json | ||
// RUN: echo "\"clangModulePath\": \"SwiftShims.pcm\"," >> %/t/map.json | ||
// RUN: echo -n "\"clangModuleCacheKey\": " >> %/t/map.json | ||
// RUN: cat %t/Shims.key >> %/t/map.json | ||
// RUN: echo "," >> %/t/map.json | ||
// RUN: echo "\"isFramework\": false" >> %/t/map.json | ||
// RUN: echo "}]" >> %/t/map.json | ||
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid | ||
|
||
// RUN: %target-swift-frontend \ | ||
// RUN: -typecheck -verify -cache-compile-job -cas-path %t/cas \ | ||
// RUN: -swift-version 5 -disable-implicit-swift-modules \ | ||
// RUN: -plugin-path %swift-plugin-dir \ | ||
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \ | ||
// RUN: -module-name MyApp -explicit-swift-module-map-file @%t/map.casid \ | ||
// RUN: %s @%t/MyApp.cmd | ||
|
||
import Swift | ||
|
||
@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary) | ||
@attached(extension, conformances: OptionSet) | ||
public macro OptionSet<RawType>() = | ||
#externalMacro(module: "SwiftMacros", type: "OptionSetMacro") | ||
|
||
@OptionSet<UInt8> | ||
struct ShippingOptions { | ||
private enum Options: Int { | ||
case nextDay | ||
case secondDay | ||
case priority | ||
case standard | ||
} | ||
|
||
static let express: ShippingOptions = [.nextDay, .secondDay] | ||
static let all: ShippingOptions = [.express, .priority, .standard] | ||
} | ||
|
||
let options = ShippingOptions.express | ||
assert(options.contains(.nextDay)) | ||
assert(options.contains(.secondDay)) | ||
assert(!options.contains(.standard)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// REQUIRES: swift_swift_parser | ||
|
||
/// Test loading and external library through `-load-plugin-library` | ||
/// TODO: switch this test case to use `-external-plugin-path`. | ||
|
||
// RUN: %empty-directory(%t) | ||
// RUN: %empty-directory(%t/plugins) | ||
// | ||
//== Build the plugin library | ||
// RUN: %host-build-swift \ | ||
// RUN: -swift-version 5 \ | ||
// RUN: -emit-library \ | ||
// RUN: -o %t/plugins/%target-library-name(MacroDefinition) \ | ||
// RUN: -module-name=MacroDefinition \ | ||
// RUN: %S/../Macros/Inputs/syntax_macro_definitions.swift \ | ||
// RUN: -g -no-toolchain-stdlib-rpath | ||
|
||
// RUN: %target-swift-frontend -scan-dependencies -module-name MyApp -module-cache-path %t/clang-module-cache -O \ | ||
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \ | ||
// RUN: %s -o %t/deps.json -swift-version 5 -cache-compile-job -cas-path %t/cas -load-plugin-library %t/plugins/%target-library-name(MacroDefinition) | ||
|
||
// RUN: %S/Inputs/SwiftDepsExtractor.py %t/deps.json MyApp casFSRootID > %t/fs.casid | ||
// RUN: llvm-cas -cas %t/cas -ls-tree-recursive @%t/fs.casid | %FileCheck %s --check-prefix=FS | ||
|
||
// FS: MacroDefinition | ||
|
||
// RUN: %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/SwiftShims.cmd | ||
// RUN: %swift_frontend_plain @%t/SwiftShims.cmd | ||
|
||
// RUN: %S/Inputs/BuildCommandExtractor.py %t/deps.json Swift > %t/Swift.cmd | ||
// RUN: %swift_frontend_plain @%t/Swift.cmd | ||
|
||
// RUN: %S/Inputs/SwiftDepsExtractor.py %t/deps.json Swift moduleCacheKey | tr -d '\n' > %t/Swift.key | ||
// RUN: %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:SwiftShims moduleCacheKey | tr -d '\n' > %t/Shims.key | ||
// RUN: %S/Inputs/BuildCommandExtractor.py %t/deps.json MyApp > %t/MyApp.cmd | ||
|
||
// RUN: echo "[{" > %/t/map.json | ||
// RUN: echo "\"moduleName\": \"Swift\"," >> %/t/map.json | ||
// RUN: echo "\"modulePath\": \"Swift.swiftmodule\"," >> %/t/map.json | ||
// RUN: echo -n "\"moduleCacheKey\": " >> %/t/map.json | ||
// RUN: cat %t/Swift.key >> %/t/map.json | ||
// RUN: echo "," >> %/t/map.json | ||
// RUN: echo "\"isFramework\": false" >> %/t/map.json | ||
// RUN: echo "}," >> %/t/map.json | ||
// RUN: echo "{" >> %/t/map.json | ||
// RUN: echo "\"moduleName\": \"SwiftShims\"," >> %/t/map.json | ||
// RUN: echo "\"clangModulePath\": \"SwiftShims.pcm\"," >> %/t/map.json | ||
// RUN: echo -n "\"clangModuleCacheKey\": " >> %/t/map.json | ||
// RUN: cat %t/Shims.key >> %/t/map.json | ||
// RUN: echo "," >> %/t/map.json | ||
// RUN: echo "\"isFramework\": false" >> %/t/map.json | ||
// RUN: echo "}]" >> %/t/map.json | ||
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid | ||
|
||
// RUN: %target-swift-frontend \ | ||
// RUN: -typecheck -verify -cache-compile-job -cas-path %t/cas \ | ||
// RUN: -swift-version 5 -disable-implicit-swift-modules \ | ||
// RUN: -load-plugin-library %t/plugins/%target-library-name(MacroDefinition) \ | ||
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \ | ||
// RUN: -module-name MyApp -explicit-swift-module-map-file @%t/map.casid \ | ||
// RUN: %s @%t/MyApp.cmd | ||
|
||
@attached(extension, conformances: P, names: named(requirement)) | ||
macro DelegatedConformance() = #externalMacro(module: "MacroDefinition", type: "DelegatedConformanceViaExtensionMacro") | ||
|
||
protocol P { | ||
static func requirement() | ||
} | ||
|
||
struct Wrapped: P { | ||
static func requirement() { | ||
print("Wrapped.requirement") | ||
} | ||
} | ||
|
||
@DelegatedConformance | ||
struct Generic<Element> {} | ||
|
||
// CHECK: {"expandMacroResult":{"diagnostics":[],"expandedSource":"extension Generic: P where Element: P {\n static func requirement() {\n Element.requirement()\n }\n}"}} | ||
|
||
func requiresP(_ value: (some P).Type) { | ||
value.requirement() | ||
} | ||
|
||
requiresP(Generic<Wrapped>.self) | ||
|
||
struct Outer { | ||
@DelegatedConformance | ||
struct Nested<Element> {} | ||
} | ||
|
||
// CHECK: {"expandMacroResult":{"diagnostics":[],"expandedSource":"extension Outer.Nested: P where Element: P {\n static func requirement() {\n Element.requirement()\n }\n}"}} | ||
|
||
requiresP(Outer.Nested<Wrapped>.self) |