Optionally show disambiguating hashes in demangled Rust identifiers (#6265)

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.
This commit is contained in:
narpfel
2024-04-02 04:58:42 +02:00
committed by GitHub
parent 815b9dda5e
commit f5efd390fa
9 changed files with 53 additions and 3 deletions

View File

@@ -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

View File

@@ -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*/}

View File

@@ -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<string, Library>, 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);
}

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -230,6 +230,8 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
private filterIntelTitle: JQuery<HTMLElement>;
private filterDemangleButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private filterDemangleTitle: JQuery<HTMLElement>;
private filterVerboseDemanglingButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private filterVerboseDemanglingTitle: JQuery<HTMLElement>;
private noBinaryFiltersButtons: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private shortCompilerName: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private bottomBar: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
@@ -1174,6 +1176,9 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
if (filters.libraryCode && !this.compiler.supportsLibraryCodeFilter) {
delete filters.libraryCode;
}
if (filters.verboseDemangling && !this.compiler.supportsVerboseDemangling) {
delete filters.verboseDemangling;
}
this.compiler.disabledFilters.forEach(filter => {
if (filters[filter]) {
delete filters[filter];
@@ -2478,6 +2483,9 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.filterDemangleButton = this.domRoot.find("[data-bind='demangle']");
this.filterDemangleTitle = this.filterDemangleButton.prop('title');
this.filterVerboseDemanglingButton = this.domRoot.find("[data-bind='verboseDemangling']");
this.filterVerboseDemanglingTitle = this.filterVerboseDemanglingButton.prop('title');
this.noBinaryFiltersButtons = this.domRoot.find('.nonbinary');
}
@@ -2741,6 +2749,14 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
// Disable demangle for compilers where we can't access it
this.filterDemangleButton.prop('disabled', !this.compiler.supportsDemangle);
formatFilterTitle(this.filterDemangleButton, this.filterDemangleTitle);
// Disable verbose demangling when demangling is disabled
this.filterVerboseDemanglingButton.prop(
'disabled',
!this.compiler.supportsVerboseDemangling || !filters.demangle,
);
formatFilterTitle(this.filterVerboseDemanglingButton, this.filterVerboseDemanglingTitle);
// Disable any of the options which don't make sense in binary mode.
const noBinaryFiltersDisabled =
(filters.binaryObject || filters.binary) && !this.compiler.supportsFiltersInBinary;
@@ -2803,6 +2819,7 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.executorButton.toggle(!!this.compiler.supportsExecute);
this.filterBinaryButton.toggle(!!this.compiler.supportsBinary);
this.filterBinaryObjectButton.toggle(!!this.compiler.supportsBinaryObject);
this.filterVerboseDemanglingButton.toggle(!!this.compiler.supportsVerboseDemangling);
this.compilerLicenseButton.toggle(!!this.hasCompilerLicenseInfo());

View File

@@ -61,6 +61,7 @@ export type CompilerInfo = {
adarts: string;
supportsDeviceAsmView?: boolean;
supportsDemangle?: boolean;
supportsVerboseDemangling?: boolean;
supportsBinary?: boolean;
supportsBinaryObject?: boolean;
supportsIntel?: boolean;

View File

@@ -33,6 +33,7 @@ export type CompilerOutputOptions = Partial<{
execute: boolean;
demangle: boolean;
intel: boolean;
verboseDemangling: boolean;
}>;
export type preProcessLinesFunc = (lines: string[]) => string[];

View File

@@ -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)