<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Thanks Brent for the tips, I think those a well-documented starter guide.</div><div class="">Two thing I couldn’t understand, and you may help.</div><div class=""><br class=""></div><div class=""><ul class="MailOutline"><li class="">I dug into the codebase as stated in the steps you mentioned, and tried to change one of the errors to see if it really change when I use Swift REPL, but nothing changed. Is it possible that I change something and directly affect the Swift compiler? (maybe I need to do a build first? Or maybe related to xcode-select?)</li><li class="">Each type of diagnostics has 4 parts, ERROR(ID,Options,Text,Signature). Diagnostics use the first 3 parts and pass parentheses to the signature. What is meant by the signature and why it’s used?</li></ul><div class=""><br class=""></div><div class="">Thanks again for the help.</div></div><span class=""><br class=""><blockquote type="cite" class="">Message: 18<br class="">Date: Thu, 9 Nov 2017 08:24:37 -0800<br class="">From: Brent Royal-Gordon <<a href="mailto:brent@architechies.com" class="">brent@architechies.com</a>><br class="">To: Mohammed Ennabah <<a href="mailto:ennabahm9@gmail.com" class="">ennabahm9@gmail.com</a>><br class="">Cc: <a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">Subject: Re: [swift-dev] SR-3423 Starter questions<br class="">Message-ID: <<a href="mailto:1C627652-F5B7-42F3-8039-1AE7BA5F7E1E@architechies.com" class="">1C627652-F5B7-42F3-8039-1AE7BA5F7E1E@architechies.com</a>><br class="">Content-Type: text/plain;<span class="Apple-tab-span" style="white-space:pre">        </span>charset=utf-8<br class=""><br class=""><blockquote type="cite" class="">On Nov 7, 2017, at 4:18 AM, Mohammed Ennabah via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:<br class=""><br class="">Hi all,<br class=""><br class="">This is the first time I work on that deep of the compiler (in SR-3423 Enum with tuple raw value not allowed) and I’m not sure where to start and what do I need to do and what files this issue is related to. It would be great if anyone guided me. Thanks.<br class=""></blockquote><br class="">This is *just* the very first step, but here's what I do when I want to debug something that involves a compiler error message:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>1. Write some code that triggers the bug and compile it.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>For instance, that bug includes a Stack Overflow link—copy that code and paste it into the Swift REPL.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>2. Pick some chunk of the error message that doesn't include any identifiers and search the Swift source code for it.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>For instance, one of the errors is "raw value for enum case must be a literal", so search for that.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>3. Most of the hits will be tests, but one will be in a .def file; that's where the error is defined. Open the file, go to that line, and get the error identifier from it.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>In this case, include/swift/AST/DiagnosticsParse.swift has this line in it:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>ERROR(nonliteral_enum_case_raw_value,PointsToFirstBadToken, "raw value for enum case must be a literal", ()) <br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>The identifier I'm talking about is the first argument to the ERROR macro—here, it's "nonliteral_enum_case_raw_value".<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>(Before you move on to the next step, look around in this file a little bit and try to get a sense for how error message strings are formatted. It may help you with future error searches.)<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>4. Search the Swift source code for that error identifier. Each hit (besides the one in the .def file) is one of the places in the compiler that can generate that error message. Read the code around each of those hits (including the name of the functions, types, files, and folders it's in) and try to figure out if it handles the specific case you want to solve, and if so, how you might be able to modify it to suit your needs.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>In this example, there is only one hit—in a .cpp file in the parser—and, a couple lines above it, you can see a dyn_cast call that checks if the expression is a literal. (`dyn_cast` is equivalent to an `as?` cast in Swift—it returns `null` if the value doesn't belong to the indicated type.) This is where the compiler is testing whether the raw value assigned to a case is a literal. You'll need to modify the code here so that it also accepts tuples of literals (and presumably, tuples of tuples of literals, and so on). There will be more to do, but that's the first step.<br class=""><br class="">When you're reading code, don't be discouraged if you don't understand it immediately. The Swift compiler is a large, complicated system, and there's lots of complicated stuff going on. Be patient, don't be afraid to jump over to another function to see what it does, and if you get stuck trying to figure out one part, move on to something else.<br class=""><br class="">I'm still very much a beginner, but this has helped me get started on a few different bugs. I hope it can help you too.<br class=""><br class="">-- <br class="">Brent Royal-Gordon<br class="">Architechies<br class=""><br class=""><br class=""><br class="">------------------------------<br class=""><br class="">Message: 19<br class="">Date: Thu, 09 Nov 2017 08:48:33 -0800<br class="">From: Daniel Dunbar <<a href="mailto:daniel_dunbar@apple.com" class="">daniel_dunbar@apple.com</a>><br class="">To: Johannes Weiss <<a href="mailto:johannesweiss@apple.com" class="">johannesweiss@apple.com</a>><br class="">Cc: swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>><br class="">Subject: Re: [swift-dev] Zero-cost 'Service Provider<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Interface'/Signature Packages<br class="">Message-ID: <<a href="mailto:E2C40795-B1CD-43FE-856A-F4C34532F53A@apple.com" class="">E2C40795-B1CD-43FE-856A-F4C34532F53A@apple.com</a>><br class="">Content-Type: text/plain; charset="utf-8"<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Nov 8, 2017, at 5:27 PM, Johannes Weiß <<a href="mailto:johannesweiss@apple.com" class="">johannesweiss@apple.com</a>> wrote:<br class=""><br class="">Hi Daniel,<br class=""><br class=""><blockquote type="cite" class="">On 2 Nov 2017, at 8:15 pm, Daniel Dunbar <<a href="mailto:daniel_dunbar@apple.com" class="">daniel_dunbar@apple.com</a>> wrote:<br class=""><br class="">My personal preference is to:<br class="">1. Do nothing for now, but encourage publishing standardized protocols to solve this need.<br class="">2. Hope for a future with WMO+LTO magic which recovers the performance, for the case where the entire application ends up using one implementation.<br class=""></blockquote><br class="">Hmm, but that'll only work if we get 'whole product optimisation', right? If we still compile one module at the time I don't think the compiler will be able to figure out that there's just one implementation of that protocol in the whole program. In fact it can't as that module might be linked into different programs and one of those programs might have a second implementation of that protocol. This is extremely likely as the 'test program' might have a mock/fake or some special implementation. Did I misunderstand you here?<br class=""></blockquote><br class="">That’s correct, that is what I meant by magic WMO+LTO future.<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">You can manage some of the “dependency injection” part by making the package which exports the common protocol also export a global variable for the concrete implementation in use (with setters). That could just be a “pattern” people follow. This wouldn’t be particularly pretty, but it would mean that intermediate packages could avoid declaring a concrete dependency on any one implementation, and leave it up to clients to pick.<br class=""></blockquote><br class="">hmm, two questions:<br class="">- what would the type of that global variable be? All libraries in the program will need to know and agree on that type<br class=""></blockquote><br class="">It would be the type of the abstract protocol.<br class=""><br class=""><blockquote type="cite" class="">- sounds like ThreadSanitizer would trap here unless we synchronise it which would make it slow again<br class=""></blockquote><br class="">Depends on how the protocol is phrased. The global instance could be a type which is instantiated and then doesn’t require locking.<br class=""><br class="">An example of what I had in mind (Package.swifts left to the reader):<br class="">```<br class="">$ find . -name \*.swift -exec printf "**** %s ****\n" {} \; -exec cat {} \;<br class="">**** ./Client/Sources/Client/main.swift ****<br class="">import Log<br class="">import BadLogger<br class=""><br class="">Log.registerLogger(BadLogger.self)<br class="">let logger = Log.createLogger()!<br class="">logger.log("how quaint")<br class=""><br class=""><br class="">**** ./BadLogger/Sources/BadLogger/BadLogger.swift ****<br class="">import Log<br class=""><br class="">public struct BadLogger: Logger {<br class=""> public init() {}<br class=""> public func log(_ message: String) {<br class=""> fatalError("logging considered harmful: \(message)")<br class=""> }<br class="">}<br class=""><br class="">**** ./Log/Sources/Log/Log.swift ****<br class="">import Dispatch<br class=""><br class="">public protocol Logger {<br class=""> // MARK: Logger API<br class=""><br class=""> init()<br class=""> func log(_ message: String)<br class="">}<br class=""><br class="">// MARK: Global Registration<br class=""><br class="">private let queue = DispatchQueue(label: "org.awesome.log")<br class="">private var theLoggerType: Logger.Type? = nil<br class=""><br class="">public func registerLogger(_ type: Logger.Type) {<br class=""> queue.sync {<br class=""> theLoggerType = type<br class=""> }<br class="">}<br class=""><br class="">public func createLogger() -> Logger? {<br class=""> return queue.sync{ theLoggerType }?.init()<br class="">}<br class="">```<br class=""><br class="">I’m not saying this is the best solution in the world, but it does work currently without requiring new features. I agree there is a (small) performance cost, but for most use cases I doubt that is the most important consideration.<br class=""><br class="">- Daniel<br class=""><br class=""><blockquote type="cite" class=""><br class=""><br class="">-- Johannes<br class=""><br class=""><blockquote type="cite" class="">- Daniel<br class=""><br class=""><blockquote type="cite" class="">On Nov 2, 2017, at 5:57 PM, Johannes Weiß via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:<br class=""><br class="">Hi swift-dev,<br class=""><br class="">I talked to a few people about this problem and we agreed that it is a problem and that it needs to be discussed. I didn't quite know where it would fit best but let's go with swift-dev, please feel free to tell to post it elsewhere if necessary. And apologies for the long mail, couldn't come up with a sensible tl;dr...<br class=""><br class="">Let me briefly introduce the problem what for the lack of a better name I call 'signature package' or 'Service Provider Interface' (SPI) as some people from the Java community seem to be calling it (<a href="https://en.wikipedia.org/wiki/Service_provider_interface" class="">https://en.wikipedia.org/wiki/Service_provider_interface</a>). For the rest of this email I'll use the term SPI.<br class=""><br class="">In a large ecosystem there is a few pieces that many libraries will depend on and yet it seems pretty much impossible to standardise exactly one implementation. Logging is a very good example as many people have different ideas about how logging should and should not work. At the moment I guess your best bet is to use your preferred logging API and hope that all your other dependencies use the same one. If not you'll likely run into annoying problems (different sub-systems logging to different places or worse).<br class=""><br class="">Also, in a world where some dependencies might be closed source this is an even bigger problem as clearly no open-source framework will depend on something that's not open-source.<br class=""><br class=""><br class="">In Java the way seems to be to standardise on some logging interface (read `protocol`) with different implementations. For logging that'd probably be SLF4J [4]. In Swift:<br class=""><br class="">let logger: LoggerProtocol = MyFavouriteLoggingFramework(configuration)<br class=""><br class="">where `LoggerProtocol` comes from some SPI package and `MyFavouriteLoggingFramework` is basically what the name says. And as a general practise, everybody would only use `LoggerProtocol`. Then tomorrow when I'll change my mind replacing `MyFavouriteLoggingFramework` by `BetterFasterLoggingFramework` does the job. With 'dependency injection' this 'logger' is handed through the whole program and there's a good chance of it all working out. The benefits are that everybody just needs to agree on a `protocol` instead of an implementation. 👍<br class=""><br class="">In Swift the downside is that this means we're now getting a virtual dispatch and the existential everywhere (which in Java will be optimised away by the JIT). That might not be a huge problem but it might undermine 'CrazyFastLoggingFramework's adoption as we always pay overhead.<br class=""><br class="">I don't think this problem can be elegantly solved today. What I could make work today (and maybe we could add language/SwiftPM support to facilitate it) is this (⚠️, it's ugly)<br class=""><br class="">- one SwiftPM package defines the SPI only, the only thing it exports is a `public protocol` called say `_spi_Logger`, no implementation<br class="">- every implementation of that SPI defines a `public struct Logger: _spi_Logger` (yes, they all share the _same_ name)<br class="">- every package that wants to log contains<br class=""><br class="">#if USE_FOO_LOGGER<br class=""> import FooLogger<br class="">#elif USE_BAR_LOGGER<br class=""> import BarLogger<br class="">#else<br class=""> import BuzLogger<br class="">#endif<br class=""><br class="">where 'BuzLogger' is the preferred logging system of this package but if either `USE_FOO_LOGGER` or `USE_BAR_LOGGER` was defined this package is happy to use those as well.<br class="">- `Logger` is always used as the type, it might be provided by different packages though<br class="">- in Package.swift of said package we'll need to define something like this:<br class=""><br class="">func loggingDependency() -> Package.Dependency {<br class="">#if USE_FOO_LOGGER<br class=""> return .package(url: "<a href="http://github.com/...../foo.git" class="">github.com/...../foo.git</a>", ...)<br class="">#elif USE_BAR_LOGGER<br class=""> return ...<br class="">#else<br class=""> return .package(url: "<a href="http://github.com/...../buz.git" class="">github.com/...../buz.git</a>", ...)<br class="">#endif<br class="">}<br class=""><br class=""> func loggingDependencyTarget() -> Target.Dependency {<br class="">#if USE_FOO_LOGGER<br class=""> return "foo"<br class="">#elif USE_BAR_LOGGER<br class=""> return "bar"<br class="">#else<br class=""> return "buz"<br class="">#endif<br class="">}<br class="">- in the dependencies array of Package.swift we'll then use `loggingDependency()` and in the target we use `loggingDependencyTarget()` instead of the concrete one<br class=""><br class="">Yes, it's awful but even in a world with different opinions about the implementation of a logger, we can make the program work.<br class="">In the happy case where application and all dependency agree that 'AwesomeLogging' is the best framework we can just type `swift build` and everything works. In the case where some dependencies think 'AwesomeLogging' is the best but others prefer 'BestEverLogging' we can force the whole application into one using `swift build -Xswiftc -DUSE_AWESOME_LOGGING` or `swift build -Xswiftc -DUSE_BEST_EVER_LOGGING`.<br class=""><br class=""><br class="">Wrapping up, I can see a few different options:<br class=""><br class="">1) do nothing and live with the situation (no Swift/SwiftPM changes required)<br class="">2) advertise something similar to what I propose above (no Swift/SwiftPM changes required)<br class="">3) do what Java does but optimise the existential away at compile time (if the compiler can prove there's actually only one type that implements that protocol)<br class="">4) teach SwiftPM about those SPI packages and make everything work, maybe by textually replacing the import statements in the source?<br class="">5) do what Haskell did and retrofit a module system that can support this<br class="">6) have 'special' `specialized protocol` for which a concrete implementation needs to be selected by the primary source<br class="">7) something I haven't thought of<br class=""><br class="">Btw, both Haskell (with the new 'backpack' [1, 2]) and ML have 'signatures' to solve this problem. A signature is basically an SPI. For an example see the backpack-str [3] module in Haskell which defines the signature (str-sig) and a bunch of different implementations for that signature (str-bytestring, str-string, str-foundation, str-text, ...).<br class=""><br class="">Let me know what you think!<br class=""><br class="">[1]: <a href="https://plv.mpi-sws.org/backpack/" class="">https://plv.mpi-sws.org/backpack/</a><br class="">[2]: <a href="https://ghc.haskell.org/trac/ghc/wiki/Backpack" class="">https://ghc.haskell.org/trac/ghc/wiki/Backpack</a><br class="">[3]: <a href="https://github.com/haskell-backpack/backpack-str" class="">https://github.com/haskell-backpack/backpack-str</a><br class="">[4]: <a href="https://www.slf4j.org/" class="">https://www.slf4j.org</a><br class=""><br class="">-- Johannes<br class="">PS: I attached a tar ball which contains the following 6 SwiftPM packages that are created like I describe above:<br class=""><br class="">- app, the main application, prefers the 'foo' logging library<br class="">- somelibA, some library which logs and prefers the 'foo' logging library<br class="">- somelibB, some other library which prefers the 'bar' logging library<br class="">- foo, the 'foo' logging library<br class="">- bar, the 'bar' logging library<br class="">- spi, the logging SPI<br class=""><br class="">The dependency default graph looks like this:<br class=""> +- somelibA ---+ foo<br class="">/ / \<br class="">app +--------------/ +-- spi<br class="">\ /<br class=""> +- somelibB ---- bar<br class=""><br class="">that looks all good, except that 'foo' and 'bar' are two logging libraries 🙈. In other words, we're in the unhappy case, therefore just typing `swift build` gives this:<br class=""><br class="">--- SNIP ---<br class="">-1- johannes:~/devel/swift-spi-demo/app<br class="">$ swift build<br class="">Compile Swift Module 'app' (1 sources)<br class="">/Users/johannes/devel/swift-spi-demo/app/Sources/app/main.swift:14:23: error: cannot convert value of type 'Logger' to expected argument type 'Logger'<br class="">somelibB_func(logger: logger)<br class=""> ^~~~~~<br class="">error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/johannes/devel/swift-spi-demo/app/.build/debug.yaml main<br class="">--- SNAP ---<br class=""><br class="">because there's two `Logger` types. But selecting `foo` gives (note that all lines start with 'Foo:'):<br class=""><br class="">--- SNIP ---<br class="">$ swift build -Xswiftc -DUSE_FOO<br class="">Compile Swift Module 'spi' (1 sources)<br class="">Compile Swift Module 'foo' (1 sources)<br class="">Compile Swift Module 'bar' (1 sources)<br class="">Compile Swift Module 'somelibB' (1 sources)<br class="">Compile Swift Module 'somelibA' (1 sources)<br class="">Compile Swift Module 'app' (1 sources)<br class="">Linking ./.build/x86_64-apple-macosx10.10/debug/app<br class="">$ ./.build/x86_64-apple-macosx10.10/debug/app<br class="">Foo: info: hello from the app<br class="">Foo: info: hello from somelibA<br class="">Foo: info: hello from somelibB<br class="">Foo: info: hello from somelibA<br class="">Foo: info: hello from somelibB<br class="">--- SNAP ---<br class=""><br class="">and for 'bar' (note that all lines start with 'Bar:')<br class=""><br class="">--- SNIP ---<br class="">$ swift build -Xswiftc -DUSE_BAR<br class="">Compile Swift Module 'spi' (1 sources)<br class="">Compile Swift Module 'foo' (1 sources)<br class="">Compile Swift Module 'bar' (1 sources)<br class="">Compile Swift Module 'somelibA' (1 sources)<br class="">Compile Swift Module 'somelibB' (1 sources)<br class="">Compile Swift Module 'app' (1 sources)<br class="">Linking ./.build/x86_64-apple-macosx10.10/debug/app<br class="">$ ./.build/x86_64-apple-macosx10.10/debug/app<br class="">Bar: info: hello from the app<br class="">Bar: info: hello from somelibA<br class="">Bar: info: hello from somelibB<br class="">Bar: info: hello from somelibA<br class="">Bar: info: hello from somelibB<br class="">--- SNAP ---<br class=""><br class=""><swift-spi-demo.tar.gz><br class=""><br class=""><br class="">_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-dev" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class=""></blockquote><br class=""></blockquote><br class=""></blockquote>-------------- next part --------------<br class="">An HTML attachment was scrubbed...<br class="">URL: <<a href="https://lists.swift.org/pipermail/swift-dev/attachments/20171109/bfd886cf/attachment-0001.html" class="">https://lists.swift.org/pipermail/swift-dev/attachments/20171109/bfd886cf/attachment-0001.html</a>><br class=""><br class="">------------------------------<br class=""><br class="">Message: 20<br class="">Date: Thu, 09 Nov 2017 09:12:27 -0800<br class="">From: Breckin Loggins <<a href="mailto:breckin@apple.com" class="">breckin@apple.com</a>><br class="">To: Brent Royal-Gordon <<a href="mailto:brent@architechies.com" class="">brent@architechies.com</a>><br class="">Cc: <a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>, Mohammed Ennabah <<a href="mailto:ennabahm9@gmail.com" class="">ennabahm9@gmail.com</a>><br class="">Subject: Re: [swift-dev] SR-3423 Starter questions<br class="">Message-ID: <<a href="mailto:76A3C32F-9F9F-4DB7-960F-DE4CBC4E21CB@apple.com" class="">76A3C32F-9F9F-4DB7-960F-DE4CBC4E21CB@apple.com</a>><br class="">Content-Type: text/plain; charset=utf-8<br class=""><br class="">This would make a great contribution to the "how to contribute" documentation; it's excellent advice.<br class=""><br class=""><blockquote type="cite" class="">On Nov 9, 2017, at 8:24 AM, Brent Royal-Gordon via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">On Nov 7, 2017, at 4:18 AM, Mohammed Ennabah via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:<br class=""><br class="">Hi all,<br class=""><br class="">This is the first time I work on that deep of the compiler (in SR-3423 Enum with tuple raw value not allowed) and I’m not sure where to start and what do I need to do and what files this issue is related to. It would be great if anyone guided me. Thanks.<br class=""></blockquote><br class="">This is *just* the very first step, but here's what I do when I want to debug something that involves a compiler error message:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>1. Write some code that triggers the bug and compile it.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>For instance, that bug includes a Stack Overflow link—copy that code and paste it into the Swift REPL.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>2. Pick some chunk of the error message that doesn't include any identifiers and search the Swift source code for it.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>For instance, one of the errors is "raw value for enum case must be a literal", so search for that.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>3. Most of the hits will be tests, but one will be in a .def file; that's where the error is defined. Open the file, go to that line, and get the error identifier from it.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>In this case, include/swift/AST/DiagnosticsParse.swift has this line in it:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>ERROR(nonliteral_enum_case_raw_value,PointsToFirstBadToken, "raw value for enum case must be a literal", ()) <br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>The identifier I'm talking about is the first argument to the ERROR macro—here, it's "nonliteral_enum_case_raw_value".<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>(Before you move on to the next step, look around in this file a little bit and try to get a sense for how error message strings are formatted. It may help you with future error searches.)<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>4. Search the Swift source code for that error identifier. Each hit (besides the one in the .def file) is one of the places in the compiler that can generate that error message. Read the code around each of those hits (including the name of the functions, types, files, and folders it's in) and try to figure out if it handles the specific case you want to solve, and if so, how you might be able to modify it to suit your needs.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>In this example, there is only one hit—in a .cpp file in the parser—and, a couple lines above it, you can see a dyn_cast call that checks if the expression is a literal. (`dyn_cast` is equivalent to an `as?` cast in Swift—it returns `null` if the value doesn't belong to the indicated type.) This is where the compiler is testing whether the raw value assigned to a case is a literal. You'll need to modify the code here so that it also accepts tuples of literals (and presumably, tuples of tuples of literals, and so on). There will be more to do, but that's the first step.<br class=""><br class="">When you're reading code, don't be discouraged if you don't understand it immediately. The Swift compiler is a large, complicated system, and there's lots of complicated stuff going on. Be patient, don't be afraid to jump over to another function to see what it does, and if you get stuck trying to figure out one part, move on to something else.<br class=""></blockquote><br class="">Another thing I've learned: don't be afraid to break it. On purpose. <br class=""><br class="">Think of the Swift repo on your machine as YOUR Swift compiler. You can make it do anything you want! Wanna make Swift look like Pascal just to figure out how the lexer and parser work? Have at it! Just because you never intend to commit a change doesn't mean it isn't valuable. <br class=""><br class="">When I don't know where to start with something in a complicated codebase, I always start by breaking something on purpose and putting a "DO NOT COMMIT" comment or warning where I do that. Now that I know I won't inadvertently check in a silly change and embarrass myself, I feel much better about exploring the code with abandon and learning about how things work by studying what happens when they don't... and that's where the learning happens for me.<br class=""><br class=""><blockquote type="cite" class=""><br class="">I'm still very much a beginner, but this has helped me get started on a few different bugs. I hope it can help you too.<br class=""></blockquote><br class="">If it helps, I still do this on codebases I've been familiar with for years when I'm changing something in an area I don't know fluently. :)<br class=""><br class=""><blockquote type="cite" class=""><br class="">-- <br class="">Brent Royal-Gordon<br class="">Architechies<br class=""><br class="">_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-dev" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class=""></blockquote><br class=""><br class=""><br class="">------------------------------<br class=""><br class="">_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-dev" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class=""><br class=""><br class="">End of swift-dev Digest, Vol 24, Issue 10<br class="">*****************************************<br class=""></blockquote></span><br class=""></div></body></html>