just to clarify since this part of Mangling.rst is a little confusing; in the following example, the module Baz is the module that contains the protocol extension on _Bar, and Foo is the module being extended, correct?
// example 2: 's3Foo4_BarP3BazE' -> (extension in Baz):Foo._Bar
// 's': language is swift
// '3Foo': namespace module is 'Foo'
// '4_BarP': protocol ('P') is '_Bar', which is 4 characters long
// '3BazE': perpetrator module is 'Baz'
moreover, since _Bar is a protocol, can we assume that _Bar was always declared by Foo?
if the module Baz were to extend _Bar with a property like qux:Int { get } , would the mangled name still be s3Foo4_BarP3BazE3quxSivg? or would it be s3Baz4_BarP3BazE3quxSivg, or something else entirely?
There’s no general way because the symbol operators don’t all have the same format. But working from the demangle tree it should always be possible to walk up the contexts until you get to a module. As demonstrated, though, it’s not always the first identifier in the symbol or anything.
is there an API in the runtime i can use to get this demangle tree? i'm really at a loss for how to filter symbols in symbolgraphs by declaring module…
It really does sound like something should expose demangle trees—one of the Syntax libraries if not the runtime itself. But then to your actual question, I’m pretty sure that information is elsewhere in symbolgraphs (not my area of expertise) and you should not be trying to do it through mangled names.
(In retrospect I wonder if the extension node is the only one that’s in the “wrong” order in mangled form, but it’s too late to change that.)