Skip to content

Commit

Permalink
Auto merge of rust-lang#119018 - matthiaskrgr:rollup-inlg0yr, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#118644 (Add test for Apple's `-weak_framework` linker argument)
 - rust-lang#118828 (Remove dead codes in rustc_codegen_gcc)
 - rust-lang#119001 (rustdoc-search: remove parallel searchWords array)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 16, 2023
2 parents e223c41 + bd7abe9 commit 5df5022
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 94 deletions.
11 changes: 0 additions & 11 deletions compiler/rustc_codegen_gcc/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,6 @@ pub trait TypeReflection<'gcc, 'tcx> {
fn is_i128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_u128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;

fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;

fn is_vector(&self) -> bool;
}

Expand Down Expand Up @@ -464,14 +461,6 @@ impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> {
self.unqualified() == cx.u128_type.unqualified()
}

fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.context.new_type::<f32>()
}

fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.context.new_type::<f64>()
}

fn is_vector(&self) -> bool {
let mut typ = self.clone();
loop {
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_codegen_gcc/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
use crate::callee::get_fn;
use crate::common::SignType;

#[derive(Clone)]
pub struct FuncSig<'gcc> {
pub params: Vec<Type<'gcc>>,
pub return_type: Type<'gcc>,
}

pub struct CodegenCx<'gcc, 'tcx> {
pub check_overflow: bool,
pub codegen_unit: &'tcx CodegenUnit<'tcx>,
Expand Down
74 changes: 28 additions & 46 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ function initSearch(rawSearchIndex) {
fullPath: ["never"],
pathWithoutLast: [],
pathLast: "never",
normalizedPathLast: "never",
generics: [],
bindings: new Map(),
typeFilter: "primitive",
Expand Down Expand Up @@ -537,12 +538,14 @@ function initSearch(rawSearchIndex) {
const bindingName = parserState.isInBinding;
parserState.isInBinding = null;
const bindings = new Map();
const pathLast = pathSegments[pathSegments.length - 1];
return {
name: name.trim(),
id: null,
fullPath: pathSegments,
pathWithoutLast: pathSegments.slice(0, pathSegments.length - 1),
pathLast: pathSegments[pathSegments.length - 1],
pathLast,
normalizedPathLast: pathLast.replace(/_/g, ""),
generics: generics.filter(gen => {
// Syntactically, bindings are parsed as generics,
// but the query engine treats them differently.
Expand Down Expand Up @@ -689,6 +692,7 @@ function initSearch(rawSearchIndex) {
fullPath: ["[]"],
pathWithoutLast: [],
pathLast: "[]",
normalizedPathLast: "[]",
generics,
typeFilter: "primitive",
bindingName: isInBinding,
Expand Down Expand Up @@ -1168,13 +1172,12 @@ function initSearch(rawSearchIndex) {
* Executes the parsed query and builds a {ResultsTable}.
*
* @param {ParsedQuery} parsedQuery - The parsed user query
* @param {Object} searchWords - The list of search words to query against
* @param {Object} [filterCrates] - Crate to search in if defined
* @param {Object} [currentCrate] - Current crate, to rank results from this crate higher
*
* @return {ResultsTable}
*/
function execQuery(parsedQuery, searchWords, filterCrates, currentCrate) {
function execQuery(parsedQuery, filterCrates, currentCrate) {
const results_others = new Map(), results_in_args = new Map(),
results_returned = new Map();

Expand Down Expand Up @@ -1232,8 +1235,8 @@ function initSearch(rawSearchIndex) {
const userQuery = parsedQuery.userQuery;
const result_list = [];
for (const result of results.values()) {
result.word = searchWords[result.id];
result.item = searchIndex[result.id] || {};
result.item = searchIndex[result.id];
result.word = searchIndex[result.id].word;
result_list.push(result);
}

Expand Down Expand Up @@ -1928,7 +1931,7 @@ function initSearch(rawSearchIndex) {
* The `results` map contains information which will be used to sort the search results:
*
* * `fullId` is a `string`` used as the key of the object we use for the `results` map.
* * `id` is the index in both `searchWords` and `searchIndex` arrays for this element.
* * `id` is the index in the `searchIndex` array for this element.
* * `index` is an `integer`` used to sort by the position of the word in the item's name.
* * `dist` is the main metric used to sort the search results.
* * `path_dist` is zero if a single-component search query is used, otherwise it's the
Expand Down Expand Up @@ -1986,9 +1989,8 @@ function initSearch(rawSearchIndex) {
if (!row || (filterCrates !== null && row.crate !== filterCrates)) {
return;
}
let index = -1, path_dist = 0;
let path_dist = 0;
const fullId = row.id;
const searchWord = searchWords[pos];

// fpDist is a minimum possible type distance, where "type distance" is the number of
// atoms in the function not present in the query
Expand Down Expand Up @@ -2021,19 +2023,10 @@ function initSearch(rawSearchIndex) {
return;
}

const row_index = row.normalizedName.indexOf(elem.pathLast);
const word_index = searchWord.indexOf(elem.pathLast);

// lower indexes are "better" matches
// rank based on the "best" match
if (row_index === -1) {
index = word_index;
} else if (word_index === -1) {
index = row_index;
} else if (word_index < row_index) {
index = word_index;
} else {
index = row_index;
let index = row.word.indexOf(elem.pathLast);
const normalizedIndex = row.normalizedName.indexOf(elem.pathLast);
if (index === -1 || (index > normalizedIndex && normalizedIndex !== -1)) {
index = normalizedIndex;
}

if (elem.fullPath.length > 1) {
Expand All @@ -2044,13 +2037,13 @@ function initSearch(rawSearchIndex) {
}

if (parsedQuery.literalSearch) {
if (searchWord === elem.name) {
if (row.word === elem.pathLast) {
addIntoResults(results_others, fullId, pos, index, 0, path_dist);
}
return;
}

const dist = editDistance(searchWord, elem.pathLast, maxEditDistance);
const dist = editDistance(row.normalizedName, elem.normalizedPathLast, maxEditDistance);

if (index === -1 && dist + path_dist > maxEditDistance) {
return;
Expand Down Expand Up @@ -2135,15 +2128,15 @@ function initSearch(rawSearchIndex) {
* @param {boolean} isAssocType
*/
function convertNameToId(elem, isAssocType) {
if (typeNameIdMap.has(elem.pathLast) &&
(isAssocType || !typeNameIdMap.get(elem.pathLast).assocOnly)) {
elem.id = typeNameIdMap.get(elem.pathLast).id;
if (typeNameIdMap.has(elem.normalizedPathLast) &&
(isAssocType || !typeNameIdMap.get(elem.normalizedPathLast).assocOnly)) {
elem.id = typeNameIdMap.get(elem.normalizedPathLast).id;
} else if (!parsedQuery.literalSearch) {
let match = null;
let matchDist = maxEditDistance + 1;
let matchName = "";
for (const [name, {id, assocOnly}] of typeNameIdMap) {
const dist = editDistance(name, elem.pathLast, maxEditDistance);
const dist = editDistance(name, elem.normalizedPathLast, maxEditDistance);
if (dist <= matchDist && dist <= maxEditDistance &&
(isAssocType || !assocOnly)) {
if (dist === matchDist && matchName > name) {
Expand Down Expand Up @@ -2236,7 +2229,7 @@ function initSearch(rawSearchIndex) {
if (parsedQuery.foundElems === 1 && parsedQuery.returned.length === 0) {
if (parsedQuery.elems.length === 1) {
const elem = parsedQuery.elems[0];
for (let i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) {
for (let i = 0, nSearchIndex = searchIndex.length; i < nSearchIndex; ++i) {
// It means we want to check for this element everywhere (in names, args and
// returned).
handleSingleArg(
Expand Down Expand Up @@ -2267,7 +2260,7 @@ function initSearch(rawSearchIndex) {
};
parsedQuery.elems.sort(sortQ);
parsedQuery.returned.sort(sortQ);
for (let i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) {
for (let i = 0, nSearchIndex = searchIndex.length; i < nSearchIndex; ++i) {
handleArgs(searchIndex[i], i, results_others);
}
}
Expand Down Expand Up @@ -2651,7 +2644,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
updateSearchHistory(buildUrl(query.original, filterCrates));

showResults(
execQuery(query, searchWords, filterCrates, window.currentCrate),
execQuery(query, filterCrates, window.currentCrate),
params.go_to_first,
filterCrates);
}
Expand Down Expand Up @@ -2920,12 +2913,6 @@ ${item.displayPath}<span class="${type}">${name}</span>\

function buildIndex(rawSearchIndex) {
searchIndex = [];
/**
* List of normalized search words (ASCII lowercased, and undescores removed).
*
* @type {Array<string>}
*/
const searchWords = [];
typeNameIdMap = new Map();
const charA = "A".charCodeAt(0);
let currentIndex = 0;
Expand Down Expand Up @@ -3004,7 +2991,6 @@ ${item.displayPath}<span class="${type}">${name}</span>\
* }}
*/
for (const [crate, crateCorpus] of rawSearchIndex) {
searchWords.push(crate);
// This object should have exactly the same set of fields as the "row"
// object defined below. Your JavaScript runtime will thank you.
// https://mathiasbynens.be/notes/shapes-ics
Expand All @@ -3017,6 +3003,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
parent: undefined,
type: null,
id: id,
word: crate,
normalizedName: crate.indexOf("_") === -1 ? crate : crate.replace(/_/g, ""),
deprecated: null,
implDisambiguator: null,
Expand Down Expand Up @@ -3084,12 +3071,9 @@ ${item.displayPath}<span class="${type}">${name}</span>\
len = itemTypes.length;
for (let i = 0; i < len; ++i) {
let word = "";
// This object should have exactly the same set of fields as the "crateRow"
// object defined above.
if (typeof itemNames[i] === "string") {
word = itemNames[i].toLowerCase();
}
searchWords.push(word);
const path = itemPaths.has(i) ? itemPaths.get(i) : lastPath;
let type = null;
if (itemFunctionSearchTypes[i] !== 0) {
Expand All @@ -3113,6 +3097,8 @@ ${item.displayPath}<span class="${type}">${name}</span>\
}
}
}
// This object should have exactly the same set of fields as the "crateRow"
// object defined above.
const row = {
crate: crate,
ty: itemTypes.charCodeAt(i) - charA,
Expand All @@ -3122,6 +3108,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined,
type,
id: id,
word,
normalizedName: word.indexOf("_") === -1 ? word : word.replace(/_/g, ""),
deprecated: deprecatedItems.has(i),
implDisambiguator: implDisambiguator.has(i) ? implDisambiguator.get(i) : null,
Expand Down Expand Up @@ -3153,7 +3140,6 @@ ${item.displayPath}<span class="${type}">${name}</span>\
}
currentIndex += itemTypes.length;
}
return searchWords;
}

/**
Expand Down Expand Up @@ -3332,10 +3318,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
search(true);
}

/**
* @type {Array<string>}
*/
const searchWords = buildIndex(rawSearchIndex);
buildIndex(rawSearchIndex);
if (typeof window !== "undefined") {
registerSearchEvents();
// If there's a search term in the URL, execute the search now.
Expand All @@ -3349,7 +3332,6 @@ ${item.displayPath}<span class="${type}">${name}</span>\
exports.execQuery = execQuery;
exports.parseQuery = parseQuery;
}
return searchWords;
}

if (typeof window !== "undefined") {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,16 @@ function loadSearchJS(doc_folder, resource_suffix) {
const staticFiles = path.join(doc_folder, "static.files");
const searchJs = fs.readdirSync(staticFiles).find(f => f.match(/search.*\.js$/));
const searchModule = require(path.join(staticFiles, searchJs));
const searchWords = searchModule.initSearch(searchIndex.searchIndex);
searchModule.initSearch(searchIndex.searchIndex);

return {
doSearch: function(queryStr, filterCrate, currentCrate) {
return searchModule.execQuery(searchModule.parseQuery(queryStr), searchWords,
return searchModule.execQuery(searchModule.parseQuery(queryStr),
filterCrate, currentCrate);
},
getCorrections: function(queryStr, filterCrate, currentCrate) {
const parsedQuery = searchModule.parseQuery(queryStr);
searchModule.execQuery(parsedQuery, searchWords, filterCrate, currentCrate);
searchModule.execQuery(parsedQuery, filterCrate, currentCrate);
return parsedQuery.correction;
},
parseQuery: searchModule.parseQuery,
Expand Down
23 changes: 23 additions & 0 deletions tests/run-make/link-framework/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# only-macos
#
# Check that linking to a framework actually makes it to the linker.

include ../tools.mk

all:
$(RUSTC) dep-link-framework.rs
$(RUSTC) dep-link-weak-framework.rs

$(RUSTC) empty.rs
otool -L $(TMPDIR)/no-link | $(CGREP) -v CoreFoundation

$(RUSTC) link-framework.rs
otool -L $(TMPDIR)/link-framework | $(CGREP) CoreFoundation | $(CGREP) -v weak

$(RUSTC) link-weak-framework.rs
otool -L $(TMPDIR)/link-weak-framework | $(CGREP) CoreFoundation | $(CGREP) weak

# When linking the framework both normally, and weakly, the weak linking takes preference

$(RUSTC) link-both.rs
otool -L $(TMPDIR)/link-both | $(CGREP) CoreFoundation | $(CGREP) weak
4 changes: 4 additions & 0 deletions tests/run-make/link-framework/dep-link-framework.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![crate_type = "rlib"]

#[link(name = "CoreFoundation", kind = "framework")]
extern "C" {}
6 changes: 6 additions & 0 deletions tests/run-make/link-framework/dep-link-weak-framework.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![crate_type = "rlib"]
#![feature(link_arg_attribute)]

#[link(name = "-weak_framework", kind = "link-arg", modifiers = "+verbatim")]
#[link(name = "CoreFoundation", kind = "link-arg", modifiers = "+verbatim")]
extern "C" {}
1 change: 1 addition & 0 deletions tests/run-make/link-framework/empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
4 changes: 4 additions & 0 deletions tests/run-make/link-framework/link-both.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extern crate dep_link_framework;
extern crate dep_link_weak_framework;

fn main() {}
3 changes: 3 additions & 0 deletions tests/run-make/link-framework/link-framework.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern crate dep_link_framework;

fn main() {}
3 changes: 3 additions & 0 deletions tests/run-make/link-framework/link-weak-framework.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern crate dep_link_weak_framework;

fn main() {}
21 changes: 0 additions & 21 deletions tests/run-pass-valgrind/osx-frameworks.rs

This file was deleted.

Loading

0 comments on commit 5df5022

Please sign in to comment.