Skip to content

Commit 3debd6b

Browse files
author
zooster
authored
Merge branch 'master' into nicedocs
2 parents 943f4eb + 9466259 commit 3debd6b

File tree

7 files changed

+133
-32
lines changed

7 files changed

+133
-32
lines changed

ci/srht/update_download_page

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ cd "$SRCTARBALLDIR/ci/srht"
100100
CIDIR="$(pwd)"
101101

102102
cd "$HOME"
103+
104+
# Upload new stdlib autodocs
105+
mkdir -p docs_to_upload/documentation/master/std/
106+
cp "$ZIGDIR/docs/std/index.html" docs_to_upload/documentation/master/std/index.html
107+
cp "$ZIGDIR/docs/std/data.js" docs_to_upload/documentation/master/std/data.js
108+
cp "$ZIGDIR/docs/std/main.js" docs_to_upload/documentation/master/std/main.js
109+
cp "$LANGREF" docs_to_upload/documentation/master/index.html
110+
$S3CMD put -P --no-mime-magic --recursive --add-header="Cache-Control: max-age=0, must-revalidate" "docs_to_upload/" s3://ziglang.org/
111+
103112
git clone --depth 1 git@github.com:ziglang/www.ziglang.org.git
104113
cd www.ziglang.org
105114
WWWDIR="$(pwd)"
@@ -108,12 +117,6 @@ $S3CMD put -P --no-mime-magic --add-header="cache-control: public, max-age=31536
108117

109118
cd "$WWWDIR"
110119
cp "$CIDIR/out/index.json" data/releases.json
111-
mkdir -p content/documentation/master/std
112-
cp "$LANGREF" content/documentation/master/index.html
113-
cp "$ZIGDIR/docs/std/index.html" content/documentation/master/std/index.html
114-
cp "$ZIGDIR/docs/std/data.js" content/documentation/master/std/data.js
115-
cp "$ZIGDIR/docs/std/main.js" content/documentation/master/std/main.js
116120
git add data/releases.json
117-
git add content/
118-
git commit -m "CI: update releases and docs"
121+
git commit -m "CI: update releases"
119122
git push origin master

lib/docs/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ <h2>Errors</h2>
650650
<div id="sectSearchResults" class="hidden">
651651
<h2>Search Results</h2>
652652
<ul id="listSearchResults"></ul>
653+
<p id="sectSearchAllResultsLink" class="hidden"><a href="">show all results</a></p>
653654
</div>
654655
<div id="sectSearchNoResults" class="hidden">
655656
<h2>No Results Found</h2>

lib/docs/main.js

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var zigAnalysis;
4040
const domDeclNoRef = document.getElementById("declNoRef");
4141
const domSearch = document.getElementById("search");
4242
const domSectSearchResults = document.getElementById("sectSearchResults");
43+
const domSectSearchAllResultsLink = document.getElementById("sectSearchAllResultsLink");
4344

4445
const domListSearchResults = document.getElementById("listSearchResults");
4546
const domSectSearchNoResults = document.getElementById("sectSearchNoResults");
@@ -51,9 +52,8 @@ var zigAnalysis;
5152
const domHelpModal = document.getElementById("helpModal");
5253
const domSearchPlaceholder = document.getElementById("searchPlaceholder");
5354

54-
domSearch.disabled = false;
55-
5655
let searchTimer = null;
56+
let searchTrimResults = true;
5757

5858
let escapeHtmlReplacements = {
5959
"&": "&amp;",
@@ -105,6 +105,7 @@ var zigAnalysis;
105105
// map of decl index to list of comptime fn calls
106106
// let nodesToCallsMap = indexNodesToCalls();
107107

108+
domSearch.disabled = false;
108109
domSearch.addEventListener("keydown", onSearchKeyDown, false);
109110
domSearch.addEventListener("focus", ev => {
110111
domSearchPlaceholder.classList.add("hidden");
@@ -113,6 +114,14 @@ var zigAnalysis;
113114
if (domSearch.value.length == 0)
114115
domSearchPlaceholder.classList.remove("hidden");
115116
});
117+
domSectSearchAllResultsLink.addEventListener('click', onClickSearchShowAllResults, false);
118+
function onClickSearchShowAllResults(ev) {
119+
ev.preventDefault();
120+
ev.stopPropagation();
121+
searchTrimResults = false;
122+
onHashChange();
123+
}
124+
116125
domPrivDeclsBox.addEventListener(
117126
"change",
118127
function () {
@@ -371,6 +380,7 @@ var zigAnalysis;
371380
domSectFns.classList.add("hidden");
372381
domSectFields.classList.add("hidden");
373382
domSectSearchResults.classList.add("hidden");
383+
domSectSearchAllResultsLink.classList.add("hidden");
374384
domSectSearchNoResults.classList.add("hidden");
375385
domSectInfo.classList.add("hidden");
376386
domHdrName.classList.add("hidden");
@@ -3273,14 +3283,14 @@ var zigAnalysis;
32733283
let oldHash = location.hash;
32743284
let parts = oldHash.split("?");
32753285
let newPart2 = domSearch.value === "" ? "" : "?" + domSearch.value;
3276-
location.hash =
3277-
parts.length === 1 ? oldHash + newPart2 : parts[0] + newPart2;
3286+
location.replace(parts.length === 1 ? oldHash + newPart2 : parts[0] + newPart2);
32783287
}
32793288
function getSearchTerms() {
32803289
let list = curNavSearch.trim().split(/[ \r\n\t]+/);
32813290
list.sort();
32823291
return list;
32833292
}
3293+
32843294
function renderSearch() {
32853295
let matchedItems = [];
32863296
let ignoreCase = curNavSearch.toLowerCase() === curNavSearch;
@@ -3346,28 +3356,37 @@ var zigAnalysis;
33463356
}
33473357

33483358
if (matchedItems.length !== 0) {
3349-
resizeDomList(
3350-
domListSearchResults,
3351-
matchedItems.length,
3352-
'<li><a href="#"></a></li>'
3353-
);
3354-
33553359
matchedItems.sort(function (a, b) {
33563360
let cmp = operatorCompare(b.points, a.points);
33573361
if (cmp != 0) return cmp;
33583362
return operatorCompare(a.decl.name, b.decl.name);
33593363
});
33603364

3365+
3366+
var searchTrimmed = false
3367+
var searchTrimResultsMaxItems = 200
3368+
if (searchTrimResults && matchedItems.length > searchTrimResultsMaxItems) {
3369+
matchedItems = matchedItems.slice(0, searchTrimResultsMaxItems)
3370+
searchTrimmed = true
3371+
}
3372+
3373+
// Build up the list of search results
3374+
let matchedItemsHTML = "";
3375+
33613376
for (let i = 0; i < matchedItems.length; i += 1) {
3362-
let liDom = domListSearchResults.children[i];
3363-
let aDom = liDom.children[0];
3364-
let match = matchedItems[i];
3365-
let lastPkgName = match.path.pkgNames[match.path.pkgNames.length - 1];
3366-
aDom.textContent = lastPkgName + "." + match.path.declNames.join(".");
3367-
aDom.setAttribute(
3368-
"href",
3369-
navLink(match.path.pkgNames, match.path.declNames)
3370-
);
3377+
const match = matchedItems[i];
3378+
const lastPkgName = match.path.pkgNames[match.path.pkgNames.length - 1];
3379+
3380+
const text = lastPkgName + "." + match.path.declNames.join(".");
3381+
const href = navLink(match.path.pkgNames, match.path.declNames);
3382+
3383+
matchedItemsHTML += "<li><a href=\""+ href +"\">"+ text + "</a></li>";
3384+
}
3385+
3386+
// Replace the search results using our newly constructed HTML string
3387+
domListSearchResults.innerHTML = matchedItemsHTML;
3388+
if (searchTrimmed) {
3389+
domSectSearchAllResultsLink.classList.remove("hidden");
33713390
}
33723391
renderSearchCursor();
33733392

src/Sema.zig

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19764,13 +19764,31 @@ fn validateRunTimeType(
1976419764
};
1976519765
}
1976619766

19767+
const TypeSet = std.HashMapUnmanaged(Type, void, Type.HashContext64, std.hash_map.default_max_load_percentage);
19768+
1976719769
fn explainWhyTypeIsComptime(
1976819770
sema: *Sema,
1976919771
block: *Block,
1977019772
src: LazySrcLoc,
1977119773
msg: *Module.ErrorMsg,
1977219774
src_loc: Module.SrcLoc,
1977319775
ty: Type,
19776+
) CompileError!void {
19777+
var type_set = TypeSet{};
19778+
defer type_set.deinit(sema.gpa);
19779+
19780+
try sema.resolveTypeFully(block, src, ty);
19781+
return sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty, &type_set);
19782+
}
19783+
19784+
fn explainWhyTypeIsComptimeInner(
19785+
sema: *Sema,
19786+
block: *Block,
19787+
src: LazySrcLoc,
19788+
msg: *Module.ErrorMsg,
19789+
src_loc: Module.SrcLoc,
19790+
ty: Type,
19791+
type_set: *TypeSet,
1977419792
) CompileError!void {
1977519793
const mod = sema.mod;
1977619794
switch (ty.zigTypeTag()) {
@@ -19808,7 +19826,7 @@ fn explainWhyTypeIsComptime(
1980819826
},
1980919827

1981019828
.Array, .Vector => {
19811-
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());
19829+
try sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty.elemType(), type_set);
1981219830
},
1981319831
.Pointer => {
1981419832
const elem_ty = ty.elemType2();
@@ -19826,45 +19844,51 @@ fn explainWhyTypeIsComptime(
1982619844
}
1982719845
return;
1982819846
}
19829-
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());
19847+
try sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty.elemType(), type_set);
1983019848
},
1983119849

1983219850
.Optional => {
1983319851
var buf: Type.Payload.ElemType = undefined;
19834-
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.optionalChild(&buf));
19852+
try sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty.optionalChild(&buf), type_set);
1983519853
},
1983619854
.ErrorUnion => {
19837-
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.errorUnionPayload());
19855+
try sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty.errorUnionPayload(), type_set);
1983819856
},
1983919857

1984019858
.Struct => {
19859+
if ((try type_set.getOrPutContext(sema.gpa, ty, .{ .mod = mod })).found_existing) return;
19860+
1984119861
if (ty.castTag(.@"struct")) |payload| {
1984219862
const struct_obj = payload.data;
1984319863
for (struct_obj.fields.values()) |field, i| {
1984419864
const field_src_loc = struct_obj.fieldSrcLoc(sema.mod, .{
1984519865
.index = i,
1984619866
.range = .type,
1984719867
});
19868+
1984819869
if (try sema.typeRequiresComptime(block, src, field.ty)) {
1984919870
try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{});
19850-
try sema.explainWhyTypeIsComptime(block, src, msg, field_src_loc, field.ty);
19871+
try sema.explainWhyTypeIsComptimeInner(block, src, msg, field_src_loc, field.ty, type_set);
1985119872
}
1985219873
}
1985319874
}
1985419875
// TODO tuples
1985519876
},
1985619877

1985719878
.Union => {
19879+
if ((try type_set.getOrPutContext(sema.gpa, ty, .{ .mod = mod })).found_existing) return;
19880+
1985819881
if (ty.cast(Type.Payload.Union)) |payload| {
1985919882
const union_obj = payload.data;
1986019883
for (union_obj.fields.values()) |field, i| {
1986119884
const field_src_loc = union_obj.fieldSrcLoc(sema.mod, .{
1986219885
.index = i,
1986319886
.range = .type,
1986419887
});
19888+
1986519889
if (try sema.typeRequiresComptime(block, src, field.ty)) {
1986619890
try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{});
19867-
try sema.explainWhyTypeIsComptime(block, src, msg, field_src_loc, field.ty);
19891+
try sema.explainWhyTypeIsComptimeInner(block, src, msg, field_src_loc, field.ty, type_set);
1986819892
}
1986919893
}
1987019894
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const S1 = struct {
2+
a: S2,
3+
};
4+
const S2 = struct {
5+
b: fn () void,
6+
};
7+
pub export fn entry() void {
8+
var s: S1 = undefined;
9+
_ = s;
10+
}
11+
12+
// error
13+
// backend=stage2
14+
// target=native
15+
//
16+
// :8:12: error: variable of type 'tmp.S1' must be const or comptime
17+
// :2:8: note: struct requires comptime because of this field
18+
// :5:8: note: struct requires comptime because of this field
19+
// :5:8: note: use '*const fn() void' for a function pointer type
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const S = struct {
2+
a: fn () void,
3+
b: *S,
4+
};
5+
pub export fn entry() void {
6+
var s: S = undefined;
7+
_ = s;
8+
}
9+
10+
11+
// error
12+
// backend=stage2
13+
// target=native
14+
//
15+
// :6:12: error: variable of type 'tmp.S' must be const or comptime
16+
// :2:8: note: struct requires comptime because of this field
17+
// :2:8: note: use '*const fn() void' for a function pointer type
18+
// :3:8: note: struct requires comptime because of this field
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const U = union {
2+
a: fn () void,
3+
b: *U,
4+
};
5+
pub export fn entry() void {
6+
var u: U = undefined;
7+
_ = u;
8+
}
9+
10+
// error
11+
// backend=stage2
12+
// target=native
13+
//
14+
// :6:12: error: variable of type 'tmp.U' must be const or comptime
15+
// :2:8: note: union requires comptime because of this field
16+
// :2:8: note: use '*const fn() void' for a function pointer type
17+
// :3:8: note: union requires comptime because of this field

0 commit comments

Comments
 (0)