From f5efd390fa7aeb8c1ab2a47de20350734fbfb597 Mon Sep 17 00:00:00 2001 From: narpfel Date: Tue, 2 Apr 2024 04:58:42 +0200 Subject: [PATCH] Optionally show disambiguating hashes in demangled Rust identifiers (#6265) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Demangled Rust identifiers under the `legacy` name mangling scheme rely on a hash to disambiguate items with the same name, such as different monomorphisations of the same function or different closures’ `call_once` methods. In the `v0` mangling scheme, this is no longer a problem. However, configuring the demangler to show hashes in `legacy` names will include crate-id hashes in `v0` names, which are [mostly unneeded](https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html#appendix-a---suggested-demangling). This PR introduces a new checkbox *Options...* → *Verbose demangling* that lets the user select if they want to include disambiguating hashes in demangled identifiers. This checkbox is only shown for compilers that support verbose demangling, and deactivated when the *Demangle identifiers* checkbox is unchecked. Resolves #1754. Resolves #6255. --- etc/config/rust.amazon.properties | 3 ++- etc/config/rust.defaults.properties | 3 ++- lib/base-compiler.ts | 6 +++++- lib/compilers/gccrs.ts | 15 +++++++++++++++ lib/compilers/rust.ts | 9 +++++++++ static/panes/compiler.ts | 17 +++++++++++++++++ types/compiler.interfaces.ts | 1 + types/features/filters.interfaces.ts | 1 + views/options-output.pug | 1 + 9 files changed, 53 insertions(+), 3 deletions(-) diff --git a/etc/config/rust.amazon.properties b/etc/config/rust.amazon.properties index b1ef00622..cfa427ee6 100644 --- a/etc/config/rust.amazon.properties +++ b/etc/config/rust.amazon.properties @@ -2,7 +2,8 @@ compilers=&rust:&rustgcc:&mrustc:&rustccggcc objdumper=/opt/compiler-explorer/gcc-13.2.0/bin/objdump linker=/opt/compiler-explorer/gcc-13.2.0/bin/gcc defaultCompiler=r1770 -demangler=/opt/compiler-explorer/demanglers/rust/bin/rustfilt +demangler=/opt/compiler-explorer/gcc-13.2.0/bin/c++filt +demanglerArgs=--format=rust buildenvsetup=ceconan-rust buildenvsetup.host=https://conan.compiler-explorer.com diff --git a/etc/config/rust.defaults.properties b/etc/config/rust.defaults.properties index 74c518980..8d04d8447 100644 --- a/etc/config/rust.defaults.properties +++ b/etc/config/rust.defaults.properties @@ -1,7 +1,8 @@ compilers=rustc supportsBinary=true compilerType=rust -demangler=${ceToolsPath}/rust/target/release/rustfilt +demangler=c++filt +demanglerArgs=--format=rust objdumper=objdump stubRe=\bmain\b stubText=pub fn main() {/*stub provided by Compiler Explorer*/} diff --git a/lib/base-compiler.ts b/lib/base-compiler.ts index 538f56031..ebb271e0b 100644 --- a/lib/base-compiler.ts +++ b/lib/base-compiler.ts @@ -846,6 +846,10 @@ export class BaseCompiler implements ICompiler { return result; } + protected optionsForDemangler(filters?: ParseFiltersAndOutputOptions): string[] { + return [...this.compiler.demanglerArgs]; + } + findAutodetectStaticLibLink(linkname: string): SelectedLibraryVersion | false { const foundLib = _.findKey(this.supportedLibraries as Record, lib => { return ( @@ -3048,7 +3052,7 @@ export class BaseCompiler implements ICompiler { async postProcessAsm(result, filters?: ParseFiltersAndOutputOptions) { if (!result.okToCache || !this.demanglerClass || !result.asm) return result; - const demangler = new this.demanglerClass(this.compiler.demangler, this, this.compiler.demanglerArgs); + const demangler = new this.demanglerClass(this.compiler.demangler, this, this.optionsForDemangler(filters)); return await demangler.process(result); } diff --git a/lib/compilers/gccrs.ts b/lib/compilers/gccrs.ts index f74568780..07938a607 100644 --- a/lib/compilers/gccrs.ts +++ b/lib/compilers/gccrs.ts @@ -23,9 +23,24 @@ // POSSIBILITY OF SUCH DAMAGE. import {GCCCompiler} from './gcc.js'; +import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; +import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; export class GCCRSCompiler extends GCCCompiler { static override get key() { return 'gccrs'; } + + constructor(info: PreliminaryCompilerInfo, env) { + super(info, env); + this.compiler.supportsVerboseDemangling = true; + } + + override optionsForDemangler(filters?: ParseFiltersAndOutputOptions): string[] { + const options = super.optionsForDemangler(filters); + if (filters !== undefined && !filters.verboseDemangling) { + options.push('--no-verbose'); + } + return options; + } } diff --git a/lib/compilers/rust.ts b/lib/compilers/rust.ts index f88dc0d65..0c2f299de 100644 --- a/lib/compilers/rust.ts +++ b/lib/compilers/rust.ts @@ -52,6 +52,7 @@ export class RustCompiler extends BaseCompiler { this.compiler.supportsIntel = true; this.compiler.supportsIrView = true; this.compiler.supportsRustMirView = true; + this.compiler.supportsVerboseDemangling = true; const isNightly = this.isNightly(); // Macro expansion (-Zunpretty=expanded) and HIR (-Zunpretty=hir-tree) @@ -222,6 +223,14 @@ export class RustCompiler extends BaseCompiler { return options; } + override optionsForDemangler(filters?: ParseFiltersAndOutputOptions): string[] { + const options = super.optionsForDemangler(filters); + if (filters !== undefined && !filters.verboseDemangling) { + options.push('--no-verbose'); + } + return options; + } + // Override the IR file name method for rustc because the output file is different from clang. override getIrOutputFilename(inputFilename: string, filters: ParseFiltersAndOutputOptions): string { const outputFilename = this.getOutputFilename(path.dirname(inputFilename), this.outputFilebase); diff --git a/static/panes/compiler.ts b/static/panes/compiler.ts index a1d53d09f..1ca2fd655 100644 --- a/static/panes/compiler.ts +++ b/static/panes/compiler.ts @@ -230,6 +230,8 @@ export class Compiler extends MonacoPane; private filterDemangleButton: JQuery; private filterDemangleTitle: JQuery; + private filterVerboseDemanglingButton: JQuery; + private filterVerboseDemanglingTitle: JQuery; private noBinaryFiltersButtons: JQuery; private shortCompilerName: JQuery; private bottomBar: JQuery; @@ -1174,6 +1176,9 @@ export class Compiler extends MonacoPane { if (filters[filter]) { delete filters[filter]; @@ -2478,6 +2483,9 @@ export class Compiler extends MonacoPane; export type preProcessLinesFunc = (lines: string[]) => string[]; diff --git a/views/options-output.pug b/views/options-output.pug index dbd620a61..78bc73c3a 100644 --- a/views/options-output.pug +++ b/views/options-output.pug @@ -20,3 +20,4 @@ mixin outputoption(name, longdescription, shortdescription, defaultchecked) +outputoption('execute', 'Execute code and show its output', 'Execute the code', false) +outputoption('intel', 'Output disassembly in Intel syntax', 'Intel asm syntax', true) +outputoption('demangle', 'Demangle output', 'Demangle identifiers', true) ++outputoption('verboseDemangling', 'Include disambiguating hashes in demangled identifiers', 'Verbose demangling', true)