Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit11a33e4

Browse files
committed
PC invalidates previous work on new run
The "up-to-date" check is not sufficient when fetchingdoc comments, since a unit may have been typechecked,with doc wrapper trees removed.A test instability was due to whether the schedulerwas checked by a callback or the runner thread.One sample file had no parser callbacks at all.
1 parent1c9aa59 commit11a33e4

File tree

11 files changed

+159
-88
lines changed

11 files changed

+159
-88
lines changed

‎src/compiler/scala/tools/nsc/Global.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,10 +1691,11 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
16911691
defcompileLate(unit:CompilationUnit):Unit= {
16921692
addUnit(unit)
16931693

1694-
if (firstPhase nenull) {// we might get here during initialization,is a source is newer than the binary
1694+
if (firstPhase nenull) {// we might get here during initialization,if a source is newer than the binary
16951695
valmaxId= math.max(globalPhase.id, typerPhase.id)
1696-
firstPhase.iterator takeWhile (_.id< maxId) foreach (ph=>
1697-
enteringPhase(ph)(ph.asInstanceOf[GlobalPhase] applyPhase unit))
1696+
firstPhase.iterator.takeWhile(_.id< maxId).foreach { ph=>
1697+
enteringPhase(ph)(ph.asInstanceOf[GlobalPhase].applyPhase(unit))
1698+
}
16981699
refreshProgress()
16991700
}
17001701
}

‎src/interactive/scala/tools/nsc/interactive/Global.scala

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
209209
/** A map that associates with each abstract file the set of responses that ware waiting
210210
* (via build) for the unit associated with the abstract file to be parsed and entered
211211
*/
212-
protectedvargetParsedEnteredResponses= newResponseMap
212+
protectedvalgetParsedEnteredResponses= newResponseMap
213213

214214
privatedefcleanResponses(rmap:ResponseMap):Unit= {
215215
for ((source, rs)<- rmap.toList) {
@@ -301,6 +301,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
301301
defisOutOfDate:Boolean= outOfDate
302302

303303
defdemandNewCompilerRun()= {
304+
if (!lastWasReload) allSources.foreach(getUnit(_).foreach(reset(_)))
304305
if (outOfDate)thrownewFreshRunReq// cancel background compile
305306
else outOfDate=true// proceed normally and enable new background compile
306307
}
@@ -428,13 +429,14 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
428429
*@parampos The position of the tree if polling while typechecking, NoPosition otherwise
429430
*
430431
*/
432+
@nowarn("cat=lint-nonlocal-return")
431433
private[interactive]defpollForWork(pos:Position):Unit= {
432434
varloop:Boolean=true
433435
while (loop) {
434-
breakable{
436+
breakable{
435437
loop=false
436438
// TODO refactor to eliminate breakable/break/return?
437-
(if (!interruptsEnabled)return):@nowarn("cat=lint-nonlocal-return")
439+
if (!interruptsEnabled)return
438440
if (pos==NoPosition|| nodesSeen% yieldPeriod==0)
439441
Thread.`yield`()
440442

@@ -447,7 +449,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
447449
caseSome(WorkEvent(id, _))=>
448450
debugLog("some work at node"+id+" current ="+nodesSeen)
449451
// assert(id >= nodesSeen)
450-
moreWorkAtNode= id
452+
moreWorkAtNode= id
451453
caseNone=>
452454
}
453455

@@ -463,7 +465,8 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
463465
debugLog("ask finished"+timeStep)
464466
interruptsEnabled=true
465467
}
466-
loop=true; break()
468+
loop=true
469+
break()
467470
case _=>
468471
}
469472

@@ -474,8 +477,8 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
474477
logreplay("exception thrown", scheduler.pollThrowable())match {
475478
caseSome(ex:FreshRunReq)=>
476479
newTyperRun()
477-
minRunId= currentRunId
478-
demandNewCompilerRun()
480+
minRunId= currentRunId
481+
demandNewCompilerRun()
479482

480483
caseSome(ShutdownReq)=>
481484
scheduler.synchronized {// lock the work queue so no more items are posted while we clean it up
@@ -497,7 +500,9 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
497500
throwShutdownReq
498501
}
499502

500-
caseSome(ex:Throwable)=> log.flush();throw ex
503+
caseSome(ex:Throwable)=>
504+
log.flush()
505+
throw ex
501506
case _=>
502507
}
503508

@@ -562,7 +567,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
562567
reporter.reset()
563568

564569
// remove any files in first that are no longer maintained by presentation compiler (i.e. closed)
565-
allSources= allSourcesfilter(s=> unitOfFilecontains(s.file))
570+
allSources= allSources.filter(s=> unitOfFile.contains(s.file))
566571

567572
// ensure all loaded units are parsed
568573
for (s<- allSources; unit<- getUnit(s)) {
@@ -582,7 +587,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
582587
}
583588

584589
// ensure all loaded units are typechecked
585-
for (s<- allSources;if!ignoredFiles(s.file); unit<- getUnit(s)) {
590+
for (s<- allSourcesif!ignoredFiles(s.file); unit<- getUnit(s))
586591
try {
587592
if (!unit.isUpToDate)
588593
if (unit.problems.isEmpty||!settings.YpresentationStrict.value)
@@ -610,7 +615,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
610615

611616
reporter.error(unit.body.pos,"Presentation compiler crashed while type checking this file: %s".format(ex.toString()))
612617
}
613-
}
614618

615619
// move units removable after this run to the "to-be-removed" buffer
616620
toBeRemoved.synchronized {
@@ -719,9 +723,11 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
719723
valresult= results.head
720724
results= results.tail
721725
if (results.isEmpty) {
722-
responsesetresult
726+
response.set(result)
723727
debugLog("responded"+timeStep)
724-
}else response setProvisionally result
728+
}
729+
else
730+
response.setProvisionally(result)
725731
}
726732
}
727733
}catch {
@@ -859,15 +865,13 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
859865

860866
privatedefwithTempUnits[T](sources:List[SourceFile])(f: (SourceFile=>RichCompilationUnit)=>T):T= {
861867
valunitOfSrc:SourceFile=>RichCompilationUnit= src=> unitOfFile(src.file)
862-
sourcesfilterNot(getUnit(_).isDefined)match {
868+
sources.filterNot(getUnit(_).isDefined)match {
863869
caseNil=>
864870
f(unitOfSrc)
865871
case unknown=>
866872
reloadSources(unknown)
867-
try {
868-
f(unitOfSrc)
869-
}finally
870-
afterRunRemoveUnitsOf(unknown)
873+
try f(unitOfSrc)
874+
finally afterRunRemoveUnitsOf(unknown)
871875
}
872876
}
873877

@@ -948,21 +952,21 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
948952
}
949953

950954
/** Implements CompilerControl.askDocComment*/
951-
private[interactive]defgetDocComment(sym:Symbol,source:SourceFile,site:Symbol,fragments:List[(Symbol,SourceFile)],
955+
private[interactive]defgetDocComment(sym:Symbol,source:SourceFile,site:Symbol,
956+
fragments:List[(Symbol,SourceFile)],
952957
response:Response[(String,String,Position)]):Unit= {
953958
informIDE(s"getDocComment$sym at$source, site$site")
954959
respond(response) {
955-
withTempUnits(fragments.unzip._2){ units=>
956-
for((sym, src)<- fragments) {
957-
valmirror= findMirrorSymbol(sym,units(src))
958-
if (mirror neNoSymbol) forceDocComment(mirror,units(src))
960+
withTempUnits(fragments.unzip._2) { unitForSrc=>
961+
for((sym, src)<- fragments) {
962+
valmirror= findMirrorSymbol(sym,unitForSrc(src))
963+
if (mirror neNoSymbol) forceDocComment(mirror,unitForSrc(src))
959964
}
960-
valmirror= findMirrorSymbol(sym,units(source))
965+
valmirror= findMirrorSymbol(sym,unitForSrc(source))
961966
if (mirror eqNoSymbol)
962967
("","",NoPosition)
963-
else {
968+
else
964969
(expandedDocComment(mirror, site), rawDocComment(mirror), docCommentPos(mirror))
965-
}
966970
}
967971
}
968972
// New typer run to remove temp units and drop per-run caches that might refer to symbols entered from temp units.

‎src/interactive/scala/tools/nsc/interactive/Response.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,13 @@ class Response[T] {
112112
complete=false
113113
cancelled=false
114114
}
115+
116+
overridedeftoString=
117+
if (!isComplete)"Response incomplete"
118+
elseif (isCancelled)"Response cancelled"
119+
else get(0L)match {
120+
caseNone=>"Response has no provisional result"
121+
caseSome(Right(t))=>s"Response failed:${t.getMessage}"
122+
caseSome(Left(data))=>s"Response data:${data}"
123+
}
115124
}

‎src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,15 @@ abstract class InteractiveTest
7575
protecteddef++(tests:PresentationCompilerTestDef*):Unit= testActions++= tests
7676

7777
/** Test's entry point*/
78-
defmain(args:Array[String]):Unit= {
79-
try execute()
80-
finally askShutdown()
81-
}
78+
defmain(args:Array[String]):Unit=try execute()finally askShutdown()
8279

83-
protecteddefexecute():Unit= {
80+
protecteddefexecute():Unit=
8481
util.stringFromStream { ostream=>
8582
Console.withOut(ostream) {
8683
loadSources()
8784
runDefaultTests()
8885
}
8986
}.linesIterator.filterNot(filterOutLines).map(normalize).foreach(println)
90-
}
9187

9288
protecteddeffilterOutLines(line:String)=false
9389
protecteddefnormalize(s:String)= s

‎src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ trait AskParse extends AskCommand {
5353
/** `sources` need to be entirely parsed before running the test
5454
* (else commands such as `AskTypeCompletionAt` may fail simply because
5555
* the source's AST is not yet loaded).
56+
*
57+
* Submit each parse job and get the response sequentially;
58+
* otherwise, parser progress update will run the next job.
5659
*/
57-
defaskParse(sources:Seq[SourceFile]):Unit= {
58-
valresponses= sources map (askParse(_))
59-
responses.foreach(_.get)// force source files parsing
60-
}
60+
defaskParse(sources:Seq[SourceFile]):Unit=
61+
for (source<- sources) {
62+
val_= askParse(source).get
63+
}
6164

6265
privatedefaskParse(src:SourceFile,keepLoaded:Boolean=true):Response[Tree]= {
6366
ask {

‎test/files/presentation/doc.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
reload:Base.scala,Class.scala, Derived.scala
1+
reload: Class.scala

‎test/files/presentation/doc/doc.scala

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//>usingoptions-Xlint-Werror
2-
importscala.reflect.internal.util.{BatchSourceFile,SourceFile}
3-
importscala.tools.nsc.doc
4-
importscala.tools.nsc.doc.base._
5-
importscala.tools.nsc.doc.base.comment._
2+
importscala.reflect.internal.util.{BatchSourceFile,SourceFile}
3+
importscala.tools.nsc.doc.{ScaladocAnalyzer,ScaladocGlobalTrait}
4+
importscala.tools.nsc.doc.base.{CommentFactoryBase,LinkTo,MemberLookupBase}
5+
importscala.tools.nsc.doc.base.comment.{Body,Comment}
66
importscala.tools.nsc.interactive._
77
importscala.tools.nsc.interactive.tests._
88

@@ -38,17 +38,17 @@ object Test extends InteractiveTest {
3838
prepre+ docComment(nTags)+ prepost+ post
3939
}
4040

41-
overridelazyvalcompiler:Global {defgetComment(sym:Symbol,source:SourceFile,fragments:List[(Symbol,SourceFile)]):Option[Comment] }= {
41+
overridelazyvalcompiler:Global {defgetComment(sym:Symbol,source:SourceFile,fragments:List[(Symbol,SourceFile)]):Option[Comment] }= {
4242
prepareSettings(settings)
43-
newGlobal(settings, compilerReporter)withMemberLookupBasewithCommentFactoryBasewithdoc.ScaladocGlobalTrait {
43+
newGlobal(settings, compilerReporter)withMemberLookupBasewithCommentFactoryBasewithScaladocGlobalTrait {
4444
outer=>
4545

4646
valglobal:this.type=this
4747

4848
@annotation.nowarn
4949
overridelazyvalanalyzer=new {
5050
valglobal: outer.type= outer
51-
}withdoc.ScaladocAnalyzerwithInteractiveAnalyzer {
51+
}withScaladocAnalyzerwithInteractiveAnalyzer {
5252
overridedefnewTyper(context:Context):InteractiveTyperwithScaladocTyper=
5353
newTyper(context)withInteractiveTyperwithScaladocTyper
5454
}
@@ -59,7 +59,7 @@ object Test extends InteractiveTest {
5959
defwarnNoLink=false
6060
deffindExternalLink(sym:Symbol,name:String)=None
6161

62-
defgetComment(sym:Symbol,source:SourceFile,fragments:List[(Symbol,SourceFile)]):Option[Comment]= {
62+
defgetComment(sym:Symbol,source:SourceFile,fragments:List[(Symbol,SourceFile)]):Option[Comment]= {
6363
valdocResponse=newResponse[(String,String,Position)]
6464
askDocComment(sym, source, sym.owner, fragments, docResponse)
6565
docResponse.get.swap.toOption flatMap {
@@ -74,12 +74,11 @@ object Test extends InteractiveTest {
7474
}
7575

7676
overridedefrunDefaultTests():Unit= {
77-
importcompiler._
77+
importcompiler.{NoSymbol,TermName,Tree,TypeName,askParsedEntered,getComment}
7878
deffindSource(name:String)= sourceFiles.find(_.file.name== name).get
7979

8080
valclassName= names.head
81-
for (name<- names;
82-
i<-1 to tags.length) {
81+
for (name<- names; i<-1 to tags.length) {
8382
valnewText= text(name, i)
8483
valsource= findSource("Class.scala")
8584
valbatch=newBatchSourceFile(source.file, newText.toCharArray)
@@ -100,12 +99,13 @@ object Test extends InteractiveTest {
10099
if (toplevel eqNoSymbol) {
101100
valclazz= compiler.rootMirror.EmptyPackage.info.decl(TypeName(className))
102101
valterm= clazz.info.decl(TermName(name))
103-
if (term eqNoSymbol) clazz.info.decl(TypeName(name))else
104-
if (term.isAccessor) term.accessedelse term
105-
}else toplevel
102+
if (term eqNoSymbol) clazz.info.decl(TypeName(name))
103+
elseif (term.isAccessor) term.accessedelse term
104+
}
105+
else toplevel
106106
}
107107

108-
getComment(sym, batch,(sym,batch)::Nil)match {
108+
getComment(sym, batch, sym->batch::Nil)match {
109109
caseNone=> println(s"Got no doc comment for$name")
110110
caseSome(comment)=>
111111
importcomment._
@@ -117,38 +117,5 @@ object Test extends InteractiveTest {
117117
}
118118
}
119119
}
120-
121-
// The remainder of this test has been found to fail intermittently on Windows
122-
// only. The problem is difficult to isolate and reproduce; see
123-
// https://github.com/scala/scala-dev/issues/72 for details.
124-
// So if we're on Windows, let's just bail out here.
125-
if (scala.util.Properties.isWin)return
126-
127-
// Check inter-classes documentation one-time retrieved ok.
128-
valbaseSource= findSource("Base.scala")
129-
valderivedSource= findSource("Derived.scala")
130-
defexistsText(where:Any,text:String):Boolean= wherematch {
131-
cases:String=> s contains text
132-
cases:Seq[_]=> s exists (existsText(_, text))
133-
casep:Product=> p.productIterator exists (existsText(_, text))
134-
casec:Comment=> existsText(c.body, text)
135-
case x=>thrownewMatchError(x)
136-
}
137-
val (derived, base)= compiler.ask { ()=>
138-
valderived= compiler.rootMirror.RootPackage.info.decl(newTermName("p")).info.decl(newTypeName("Derived"))
139-
(derived, derived.ancestors(0))
140-
}
141-
valcmt1= getComment(derived, derivedSource, (base, baseSource)::(derived, derivedSource)::Nil)
142-
if (!existsText(cmt1,"This is Derived comment"))
143-
println("Unexpected Derived class comment:"+cmt1)
144-
145-
val (fooDerived, fooBase)= compiler.ask { ()=>
146-
valdecl= derived.tpe.decl(newTermName("foo"))
147-
(decl, decl.allOverriddenSymbols(0))
148-
}
149-
150-
valcmt2= getComment(fooDerived, derivedSource, (fooBase, baseSource)::(fooDerived, derivedSource)::Nil)
151-
if (!existsText(cmt2,"Base method has documentation"))
152-
println("Unexpected foo method comment:"+cmt2)
153120
}
154121
}

‎test/files/presentation/dock.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
reload: Base.scala, Derived.scala

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp