Merge branch 'master' into nicedocs

This commit is contained in:
zooster 2022-08-06 19:32:42 +02:00 committed by GitHub
commit 3debd6b732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 133 additions and 32 deletions

View File

@ -100,6 +100,15 @@ cd "$SRCTARBALLDIR/ci/srht"
CIDIR="$(pwd)"
cd "$HOME"
# Upload new stdlib autodocs
mkdir -p docs_to_upload/documentation/master/std/
cp "$ZIGDIR/docs/std/index.html" docs_to_upload/documentation/master/std/index.html
cp "$ZIGDIR/docs/std/data.js" docs_to_upload/documentation/master/std/data.js
cp "$ZIGDIR/docs/std/main.js" docs_to_upload/documentation/master/std/main.js
cp "$LANGREF" docs_to_upload/documentation/master/index.html
$S3CMD put -P --no-mime-magic --recursive --add-header="Cache-Control: max-age=0, must-revalidate" "docs_to_upload/" s3://ziglang.org/
git clone --depth 1 git@github.com:ziglang/www.ziglang.org.git
cd www.ziglang.org
WWWDIR="$(pwd)"
@ -108,12 +117,6 @@ $S3CMD put -P --no-mime-magic --add-header="cache-control: public, max-age=31536
cd "$WWWDIR"
cp "$CIDIR/out/index.json" data/releases.json
mkdir -p content/documentation/master/std
cp "$LANGREF" content/documentation/master/index.html
cp "$ZIGDIR/docs/std/index.html" content/documentation/master/std/index.html
cp "$ZIGDIR/docs/std/data.js" content/documentation/master/std/data.js
cp "$ZIGDIR/docs/std/main.js" content/documentation/master/std/main.js
git add data/releases.json
git add content/
git commit -m "CI: update releases and docs"
git commit -m "CI: update releases"
git push origin master

View File

@ -650,6 +650,7 @@
<div id="sectSearchResults" class="hidden">
<h2>Search Results</h2>
<ul id="listSearchResults"></ul>
<p id="sectSearchAllResultsLink" class="hidden"><a href="">show all results</a></p>
</div>
<div id="sectSearchNoResults" class="hidden">
<h2>No Results Found</h2>

View File

@ -40,6 +40,7 @@ var zigAnalysis;
const domDeclNoRef = document.getElementById("declNoRef");
const domSearch = document.getElementById("search");
const domSectSearchResults = document.getElementById("sectSearchResults");
const domSectSearchAllResultsLink = document.getElementById("sectSearchAllResultsLink");
const domListSearchResults = document.getElementById("listSearchResults");
const domSectSearchNoResults = document.getElementById("sectSearchNoResults");
@ -51,9 +52,8 @@ var zigAnalysis;
const domHelpModal = document.getElementById("helpModal");
const domSearchPlaceholder = document.getElementById("searchPlaceholder");
domSearch.disabled = false;
let searchTimer = null;
let searchTrimResults = true;
let escapeHtmlReplacements = {
"&": "&amp;",
@ -105,6 +105,7 @@ var zigAnalysis;
// map of decl index to list of comptime fn calls
// let nodesToCallsMap = indexNodesToCalls();
domSearch.disabled = false;
domSearch.addEventListener("keydown", onSearchKeyDown, false);
domSearch.addEventListener("focus", ev => {
domSearchPlaceholder.classList.add("hidden");
@ -113,6 +114,14 @@ var zigAnalysis;
if (domSearch.value.length == 0)
domSearchPlaceholder.classList.remove("hidden");
});
domSectSearchAllResultsLink.addEventListener('click', onClickSearchShowAllResults, false);
function onClickSearchShowAllResults(ev) {
ev.preventDefault();
ev.stopPropagation();
searchTrimResults = false;
onHashChange();
}
domPrivDeclsBox.addEventListener(
"change",
function () {
@ -371,6 +380,7 @@ var zigAnalysis;
domSectFns.classList.add("hidden");
domSectFields.classList.add("hidden");
domSectSearchResults.classList.add("hidden");
domSectSearchAllResultsLink.classList.add("hidden");
domSectSearchNoResults.classList.add("hidden");
domSectInfo.classList.add("hidden");
domHdrName.classList.add("hidden");
@ -3273,14 +3283,14 @@ var zigAnalysis;
let oldHash = location.hash;
let parts = oldHash.split("?");
let newPart2 = domSearch.value === "" ? "" : "?" + domSearch.value;
location.hash =
parts.length === 1 ? oldHash + newPart2 : parts[0] + newPart2;
location.replace(parts.length === 1 ? oldHash + newPart2 : parts[0] + newPart2);
}
function getSearchTerms() {
let list = curNavSearch.trim().split(/[ \r\n\t]+/);
list.sort();
return list;
}
function renderSearch() {
let matchedItems = [];
let ignoreCase = curNavSearch.toLowerCase() === curNavSearch;
@ -3346,28 +3356,37 @@ var zigAnalysis;
}
if (matchedItems.length !== 0) {
resizeDomList(
domListSearchResults,
matchedItems.length,
'<li><a href="#"></a></li>'
);
matchedItems.sort(function (a, b) {
let cmp = operatorCompare(b.points, a.points);
if (cmp != 0) return cmp;
return operatorCompare(a.decl.name, b.decl.name);
});
var searchTrimmed = false
var searchTrimResultsMaxItems = 200
if (searchTrimResults && matchedItems.length > searchTrimResultsMaxItems) {
matchedItems = matchedItems.slice(0, searchTrimResultsMaxItems)
searchTrimmed = true
}
// Build up the list of search results
let matchedItemsHTML = "";
for (let i = 0; i < matchedItems.length; i += 1) {
let liDom = domListSearchResults.children[i];
let aDom = liDom.children[0];
let match = matchedItems[i];
let lastPkgName = match.path.pkgNames[match.path.pkgNames.length - 1];
aDom.textContent = lastPkgName + "." + match.path.declNames.join(".");
aDom.setAttribute(
"href",
navLink(match.path.pkgNames, match.path.declNames)
);
const match = matchedItems[i];
const lastPkgName = match.path.pkgNames[match.path.pkgNames.length - 1];
const text = lastPkgName + "." + match.path.declNames.join(".");
const href = navLink(match.path.pkgNames, match.path.declNames);
matchedItemsHTML += "<li><a href=\""+ href +"\">"+ text + "</a></li>";
}
// Replace the search results using our newly constructed HTML string
domListSearchResults.innerHTML = matchedItemsHTML;
if (searchTrimmed) {
domSectSearchAllResultsLink.classList.remove("hidden");
}
renderSearchCursor();

View File

@ -19764,6 +19764,8 @@ fn validateRunTimeType(
};
}
const TypeSet = std.HashMapUnmanaged(Type, void, Type.HashContext64, std.hash_map.default_max_load_percentage);
fn explainWhyTypeIsComptime(
sema: *Sema,
block: *Block,
@ -19771,6 +19773,22 @@ fn explainWhyTypeIsComptime(
msg: *Module.ErrorMsg,
src_loc: Module.SrcLoc,
ty: Type,
) CompileError!void {
var type_set = TypeSet{};
defer type_set.deinit(sema.gpa);
try sema.resolveTypeFully(block, src, ty);
return sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty, &type_set);
}
fn explainWhyTypeIsComptimeInner(
sema: *Sema,
block: *Block,
src: LazySrcLoc,
msg: *Module.ErrorMsg,
src_loc: Module.SrcLoc,
ty: Type,
type_set: *TypeSet,
) CompileError!void {
const mod = sema.mod;
switch (ty.zigTypeTag()) {
@ -19808,7 +19826,7 @@ fn explainWhyTypeIsComptime(
},
.Array, .Vector => {
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());
try sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty.elemType(), type_set);
},
.Pointer => {
const elem_ty = ty.elemType2();
@ -19826,18 +19844,20 @@ fn explainWhyTypeIsComptime(
}
return;
}
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());
try sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty.elemType(), type_set);
},
.Optional => {
var buf: Type.Payload.ElemType = undefined;
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.optionalChild(&buf));
try sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty.optionalChild(&buf), type_set);
},
.ErrorUnion => {
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.errorUnionPayload());
try sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty.errorUnionPayload(), type_set);
},
.Struct => {
if ((try type_set.getOrPutContext(sema.gpa, ty, .{ .mod = mod })).found_existing) return;
if (ty.castTag(.@"struct")) |payload| {
const struct_obj = payload.data;
for (struct_obj.fields.values()) |field, i| {
@ -19845,9 +19865,10 @@ fn explainWhyTypeIsComptime(
.index = i,
.range = .type,
});
if (try sema.typeRequiresComptime(block, src, field.ty)) {
try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{});
try sema.explainWhyTypeIsComptime(block, src, msg, field_src_loc, field.ty);
try sema.explainWhyTypeIsComptimeInner(block, src, msg, field_src_loc, field.ty, type_set);
}
}
}
@ -19855,6 +19876,8 @@ fn explainWhyTypeIsComptime(
},
.Union => {
if ((try type_set.getOrPutContext(sema.gpa, ty, .{ .mod = mod })).found_existing) return;
if (ty.cast(Type.Payload.Union)) |payload| {
const union_obj = payload.data;
for (union_obj.fields.values()) |field, i| {
@ -19862,9 +19885,10 @@ fn explainWhyTypeIsComptime(
.index = i,
.range = .type,
});
if (try sema.typeRequiresComptime(block, src, field.ty)) {
try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{});
try sema.explainWhyTypeIsComptime(block, src, msg, field_src_loc, field.ty);
try sema.explainWhyTypeIsComptimeInner(block, src, msg, field_src_loc, field.ty, type_set);
}
}
}

View File

@ -0,0 +1,19 @@
const S1 = struct {
a: S2,
};
const S2 = struct {
b: fn () void,
};
pub export fn entry() void {
var s: S1 = undefined;
_ = s;
}
// error
// backend=stage2
// target=native
//
// :8:12: error: variable of type 'tmp.S1' must be const or comptime
// :2:8: note: struct requires comptime because of this field
// :5:8: note: struct requires comptime because of this field
// :5:8: note: use '*const fn() void' for a function pointer type

View File

@ -0,0 +1,18 @@
const S = struct {
a: fn () void,
b: *S,
};
pub export fn entry() void {
var s: S = undefined;
_ = s;
}
// error
// backend=stage2
// target=native
//
// :6:12: error: variable of type 'tmp.S' must be const or comptime
// :2:8: note: struct requires comptime because of this field
// :2:8: note: use '*const fn() void' for a function pointer type
// :3:8: note: struct requires comptime because of this field

View File

@ -0,0 +1,17 @@
const U = union {
a: fn () void,
b: *U,
};
pub export fn entry() void {
var u: U = undefined;
_ = u;
}
// error
// backend=stage2
// target=native
//
// :6:12: error: variable of type 'tmp.U' must be const or comptime
// :2:8: note: union requires comptime because of this field
// :2:8: note: use '*const fn() void' for a function pointer type
// :3:8: note: union requires comptime because of this field